update non-reset-packs semantics

This commit is contained in:
MihailRis 2025-11-10 12:23:35 +03:00
parent b0d662f845
commit a4461a7dc3
5 changed files with 27 additions and 5 deletions

View File

@ -186,7 +186,6 @@ events = require "core:internal/events"
function pack.unload(prefix)
events.remove_by_prefix(prefix)
__vc__pack_envs[prefix] = nil
end
function __vc_start_app_script(path)

View File

@ -771,6 +771,7 @@ function __scripts_cleanup(non_reset_packs)
__cached_scripts[k] = nil
package.loaded[k] = nil
end
__vc__pack_envs[packname] = nil
::continue::
end
end

View File

@ -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;

View File

@ -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) {

View File

@ -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);