move events library implementation to core:internal/events & disable access to core:internal modules outside of stdlib

This commit is contained in:
MihailRis
2025-08-08 00:29:12 +03:00
parent 5785b9fdda
commit 3760fb86f7
6 changed files with 67 additions and 59 deletions
+11
View File
@@ -550,6 +550,8 @@ function reload_module(name)
end
end
local internal_locked = false
-- Load script with caching
--
-- path - script path `contentpack:filename`.
@@ -559,6 +561,11 @@ end
function __load_script(path, nocache)
local packname, filename = parse_path(path)
if internal_locked and (packname == "res" or packname == "core")
and filename:starts_with("modules/internal") then
error("access to core:internal modules outside of [core]")
end
-- __cached_scripts used in condition because cached result may be nil
if not nocache and __cached_scripts[path] ~= nil then
return package.loaded[path]
@@ -579,6 +586,10 @@ function __load_script(path, nocache)
return result
end
function __vc_lock_internal_modules()
internal_locked = true
end
function require(path)
if not string.find(path, ':') then
local prefix, _ = parse_path(_debug_getinfo(2).source)