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

@ -540,20 +540,27 @@ function __vc_on_world_save()
file.write(RULES_FILE, toml.tostring(rule_values))
end
local __close_all_descriptors = file.__close_all_descriptors
local __gui_util_reset_local = gui_util.__reset_local
local __stdcomp_reset = stdcomp.__reset
file.__close_all_descriptors = nil
gui_util.__reset_local = nil
stdcomp.reset = nil
function __vc_on_world_quit()
_rules.clear()
gui_util:__reset_local()
stdcomp.__reset()
file.__close_all_descriptors()
__gui_util_reset_local()
__stdcomp_reset()
__close_all_descriptors()
end
local __post_runnables = {}
local fn_audio_reset_fetch_buffer = audio.__reset_fetch_buffer
audio.__reset_fetch_buffer = nil
core.get_core_token = audio.input.__get_core_token
local function __vc__process_post_runnables()
local __post_runnables = {}
local function __process_post_runnables()
if #__post_runnables > 0 then
for _, func in ipairs(__post_runnables) do
local status, result = xpcall(func, __vc__error)
@ -587,9 +594,9 @@ local function __vc__process_post_runnables()
end
end
function __process_post_runnables()
function __vc__process_post_runnables()
__vc__is_post_runnable = true
local success, err = pcall(__vc__process_post_runnables)
local success, err = pcall(__process_post_runnables)
if not success then
debug.error("an error ocurred while processing post-runnables: ".. err)
end
@ -624,3 +631,4 @@ require "core:internal/deprecated"
ffi = nil
__vc_app = nil
__vc_lock_internal_modules()
__vc_lock_internal_modules = nil

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