cleanup internal functions

This commit is contained in:
MihailRis 2026-04-27 00:24:25 +03:00
parent ab179881e8
commit 629f672d38
6 changed files with 37 additions and 24 deletions

View file

@ -192,7 +192,7 @@ function reload_module(name)
end
end
local internal_locked = false
local __internal_locked = false
-- Load script with caching
--
@ -202,9 +202,12 @@ local internal_locked = false
-- nocache - ignore cached script, load anyway
function __load_script(path, nocache, env)
local packname, filename = parse_path(path)
local is_internal = (packname == "res" or packname == "core")
and filename:find("modules/internal") == 1
if internal_locked and (packname == "res" or packname == "core")
and filename:starts_with("modules/internal") then
nocache = nocache or is_internal
if is_internal and __internal_locked then
error("access to core:internal modules outside of [core]")
end
@ -232,16 +235,19 @@ function __load_script(path, nocache, env)
end
function __vc_lock_internal_modules()
internal_locked = true
__internal_locked = true
end
local __pack_envs = __vc__pack_envs
__vc__pack_envs = nil
function require(path)
if not string.find(path, ':') then
local prefix, _ = parse_path(_debug_getinfo(2).source)
return require(prefix .. ':' .. path)
end
local prefix, file = parse_path(path)
local env = __vc__pack_envs[prefix]
local env = __pack_envs[prefix]
return __load_script(prefix .. ":modules/" .. file .. ".lua", nil, env)
end
@ -262,7 +268,7 @@ function __scripts_cleanup(non_reset_packs)
__cached_scripts[k] = nil
package.loaded[k] = nil
end
__vc__pack_envs[packname] = nil
__pack_envs[packname] = nil
::continue::
end
end