Merge branch 'master' into jgrpp
# Conflicts: # cmake/CompileFlags.cmake # src/cargomonitor.cpp # src/core/CMakeLists.txt # src/economy.cpp # src/landscape.cpp # src/linkgraph/flowmapper.cpp # src/linkgraph/linkgraph_gui.cpp # src/linkgraph/linkgraphschedule.cpp # src/misc_gui.cpp # src/newgrf_generic.cpp # src/newgrf_storage.cpp # src/rail_gui.cpp # src/saveload/afterload.cpp # src/saveload/station_sl.cpp # src/script/script_gui.cpp # src/station_cmd.cpp # src/station_gui.cpp # src/string_func.h # src/terraform_cmd.cpp
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "../script_gui.h"
|
||||
#include "../../settings_type.h"
|
||||
#include "../../network/network.h"
|
||||
#include "../../3rdparty/fmt/format.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
@@ -75,16 +76,6 @@ ScriptController::ScriptController(CompanyID company) :
|
||||
ScriptObject::SetCompany(company);
|
||||
}
|
||||
|
||||
ScriptController::~ScriptController()
|
||||
{
|
||||
for (const auto &item : this->loaded_library) {
|
||||
free(item.second);
|
||||
free(item.first);
|
||||
}
|
||||
|
||||
this->loaded_library.clear();
|
||||
}
|
||||
|
||||
/* static */ uint ScriptController::GetTick()
|
||||
{
|
||||
return ScriptObject::GetActiveInstance()->GetController()->ticks;
|
||||
@@ -124,24 +115,22 @@ ScriptController::~ScriptController()
|
||||
}
|
||||
|
||||
/* Internally we store libraries as 'library.version' */
|
||||
char library_name[1024];
|
||||
seprintf(library_name, lastof(library_name), "%s.%d", library, version);
|
||||
strtolower(library_name);
|
||||
std::string library_name = fmt::format("{}.{}", library, version);
|
||||
|
||||
/* Get the current table/class we belong to */
|
||||
HSQOBJECT parent;
|
||||
sq_getstackobj(vm, 1, &parent);
|
||||
|
||||
char fake_class[1024];
|
||||
std::string fake_class;
|
||||
|
||||
LoadedLibraryList::iterator it = controller->loaded_library.find(library_name);
|
||||
if (it != controller->loaded_library.end()) {
|
||||
strecpy(fake_class, (*it).second, lastof(fake_class));
|
||||
fake_class = (*it).second;
|
||||
} else {
|
||||
int next_number = ++controller->loaded_library_count;
|
||||
|
||||
/* Create a new fake internal name */
|
||||
seprintf(fake_class, lastof(fake_class), "_internalNA%d", next_number);
|
||||
fake_class = fmt::format("_internalNA{}", next_number);
|
||||
|
||||
/* Load the library in a 'fake' namespace, so we can link it to the name the user requested */
|
||||
sq_pushroottable(vm);
|
||||
@@ -157,7 +146,7 @@ ScriptController::~ScriptController()
|
||||
sq_newslot(vm, -3, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
|
||||
controller->loaded_library[stredup(library_name)] = stredup(fake_class);
|
||||
controller->loaded_library[library_name] = fake_class;
|
||||
}
|
||||
|
||||
/* Find the real class inside the fake class (like 'sets.Vector') */
|
||||
|
Reference in New Issue
Block a user