update non-reset-packs semantics
This commit is contained in:
parent
b0d662f845
commit
a4461a7dc3
@ -186,7 +186,6 @@ events = require "core:internal/events"
|
|||||||
|
|
||||||
function pack.unload(prefix)
|
function pack.unload(prefix)
|
||||||
events.remove_by_prefix(prefix)
|
events.remove_by_prefix(prefix)
|
||||||
__vc__pack_envs[prefix] = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function __vc_start_app_script(path)
|
function __vc_start_app_script(path)
|
||||||
|
|||||||
@ -771,6 +771,7 @@ function __scripts_cleanup(non_reset_packs)
|
|||||||
__cached_scripts[k] = nil
|
__cached_scripts[k] = nil
|
||||||
package.loaded[k] = nil
|
package.loaded[k] = nil
|
||||||
end
|
end
|
||||||
|
__vc__pack_envs[packname] = nil
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -336,6 +336,22 @@ int lua::create_environment(State* L, int parent) {
|
|||||||
return id;
|
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) {
|
void lua::remove_environment(State* L, int id) {
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -614,6 +614,7 @@ namespace lua {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int create_environment(lua::State*, int parent);
|
int create_environment(lua::State*, int parent);
|
||||||
|
int restore_pack_environment(lua::State*, const std::string& packid);
|
||||||
void remove_environment(lua::State*, int id);
|
void remove_environment(lua::State*, int id);
|
||||||
|
|
||||||
inline void close(lua::State* L) {
|
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
|
const ContentPack& pack
|
||||||
) {
|
) {
|
||||||
auto L = lua::get_main_state();
|
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::pushenv(L, id);
|
||||||
lua::pushvalue(L, -1);
|
lua::pushvalue(L, -1);
|
||||||
lua::setfield(L, "PACK_ENV");
|
lua::setfield(L, "PACK_ENV");
|
||||||
@ -352,9 +360,6 @@ void scripting::cleanup(const std::vector<std::string>& nonReset) {
|
|||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
lua::requireglobal(L, "pack");
|
lua::requireglobal(L, "pack");
|
||||||
for (auto& pack : content_control->getAllContentPacks()) {
|
for (auto& pack : content_control->getAllContentPacks()) {
|
||||||
if (std::find(nonReset.begin(), nonReset.end(), pack.id) != nonReset.end()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
lua::requirefield(L, "unload");
|
lua::requirefield(L, "unload");
|
||||||
lua::pushstring(L, pack.id);
|
lua::pushstring(L, pack.id);
|
||||||
lua::call_nothrow(L, 1);
|
lua::call_nothrow(L, 1);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user