mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 14:01:49 +00:00
fix reload_module ignoring pack environment
reload_module loaded the new module code with the global environment, while require runs modules in their pack environment. After reload, PACK_ID and other pack globals were nil in the module.
This commit is contained in:
parent
e8a83423d8
commit
d8017ff995
2 changed files with 43 additions and 6 deletions
|
|
@ -183,6 +183,12 @@ function on_deprecated_call(name, alternatives)
|
|||
end
|
||||
end
|
||||
|
||||
local __pack_envs = __vc__pack_envs
|
||||
function __vc_internals.get_pack_env(packid)
|
||||
return __pack_envs[packid]
|
||||
end
|
||||
__vc__pack_envs = nil
|
||||
|
||||
function reload_module(name)
|
||||
local prefix, name = parse_path(name)
|
||||
local path = prefix..":modules/"..name..".lua"
|
||||
|
|
@ -196,6 +202,10 @@ function reload_module(name)
|
|||
if script == nil then
|
||||
error(err)
|
||||
end
|
||||
local env = __pack_envs[prefix]
|
||||
if env then
|
||||
script = setfenv(script, env)
|
||||
end
|
||||
local result = script()
|
||||
if not result then
|
||||
return
|
||||
|
|
@ -270,12 +280,6 @@ function __vc_lock_internal_modules()
|
|||
__internal_locked = true
|
||||
end
|
||||
|
||||
local __pack_envs = __vc__pack_envs
|
||||
function __vc_internals.get_pack_env(packid)
|
||||
return __pack_envs[packid]
|
||||
end
|
||||
__vc__pack_envs = nil
|
||||
|
||||
function require(path)
|
||||
if not string.find(path, ':') then
|
||||
local prefix, _ = parse_path(_debug_getinfo(2).source)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue