update non-reset-packs semantics
This commit is contained in:
@@ -336,6 +336,22 @@ int lua::create_environment(State* L, int parent) {
|
||||
return id;
|
||||
}
|
||||
|
||||
int lua::restore_pack_environment(lua::State* L, const std::string& packid) {
|
||||
if(!lua::getglobal(L, "__vc__pack_envs")) {
|
||||
return -1;
|
||||
}
|
||||
int id = nextEnvironment++;
|
||||
|
||||
if (lua::getfield(L, packid)) {
|
||||
// envname = env
|
||||
setglobal(L, env_name(id));
|
||||
lua::pop(L);
|
||||
return id;
|
||||
}
|
||||
lua::pop(L);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void lua::remove_environment(State* L, int id) {
|
||||
if (id == 0) {
|
||||
return;
|
||||
|
||||
@@ -614,6 +614,7 @@ namespace lua {
|
||||
return 0;
|
||||
}
|
||||
int create_environment(lua::State*, int parent);
|
||||
int restore_pack_environment(lua::State*, const std::string& packid);
|
||||
void remove_environment(lua::State*, int id);
|
||||
|
||||
inline void close(lua::State* L) {
|
||||
|
||||
@@ -173,7 +173,15 @@ std::unique_ptr<Process> scripting::start_app_script(const io::path& script) {
|
||||
const ContentPack& pack
|
||||
) {
|
||||
auto L = lua::get_main_state();
|
||||
int id = lua::create_environment(L, 0);
|
||||
int id = lua::restore_pack_environment(L, pack.id);
|
||||
if (id != -1) {
|
||||
return std::shared_ptr<int>(new int(id), [=](int* id) { //-V508
|
||||
lua::remove_environment(L, *id);
|
||||
delete id;
|
||||
});
|
||||
}
|
||||
id = lua::create_environment(L, 0);
|
||||
|
||||
lua::pushenv(L, id);
|
||||
lua::pushvalue(L, -1);
|
||||
lua::setfield(L, "PACK_ENV");
|
||||
@@ -352,9 +360,6 @@ void scripting::cleanup(const std::vector<std::string>& nonReset) {
|
||||
auto L = lua::get_main_state();
|
||||
lua::requireglobal(L, "pack");
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
if (std::find(nonReset.begin(), nonReset.end(), pack.id) != nonReset.end()) {
|
||||
continue;
|
||||
}
|
||||
lua::requirefield(L, "unload");
|
||||
lua::pushstring(L, pack.id);
|
||||
lua::call_nothrow(L, 1);
|
||||
|
||||
Reference in New Issue
Block a user