Merge branch 'main' into animation

This commit is contained in:
MihailRis 2026-08-22 00:36:25 +03:00
commit d20e9fcb40
18 changed files with 242 additions and 124 deletions

View file

@ -1,3 +1,6 @@
local app = __vc_app
local internals = __vc_internals
local user_props = file.read_combined_object("config/user-props.toml")
local names = {
"parent", "caption", "texture", "texture-faces", "model", "model-name",
@ -42,7 +45,7 @@ local function make_read_only(t)
__newindex = function()
error("table is read-only")
end
})
})
end
make_read_only(block.properties)
@ -85,3 +88,33 @@ cache_names(block)
cache_names(item)
__vc_scripts_registry.build_registry()
local packs = app.get_content()
table.insert(packs, 1, "core")
for i, packid in ipairs(packs) do
local loaders_dir = packid..":scripts/loaders"
if not file.isdir(loaders_dir) then
goto continue
end
local files = file.list(loaders_dir)
for _, path in ipairs(files) do
if file.ext(path) == "json" then
debug.log("registering loader "..path)
local dto = json.parse(file.read(path))
local module = setmetatable({}, {__index=internals.get_pack_env(packid)})
local module_path = file.join(file.parent(path), file.stem(path)..".lua")
if not file.exists(module_path) then
error("loader "..path.." missing module "..module_path)
end
load(file.read(module_path), module_path, "t", module)()
if rawget(module, "execute") == nil then
error("loader "..path.." missing function 'execute'")
end
if dto.type == "compiler" then
internals.register_compiler(packid, dto.extensions, module)
end
end
end
::continue::
end

View file

@ -392,6 +392,7 @@ end
ffi = nil
__vc_app = nil
__vc_internals = nil
__vc_lock_internal_modules()
__vc_lock_internal_modules = nil
__vc_update_coroutines = nil

View file

@ -154,6 +154,20 @@ package = {
}
local __cached_scripts = {}
local __warnings_hidden = {}
local __compilers = {}
function __vc_internals.register_compiler(sourcepack, extensions, module)
local compiler = {
packid = sourcepack,
extensions = extensions,
module = module,
}
for i, ext in ipairs(extensions) do
if not __compilers[ext] then
__compilers[ext] = compiler
end
end
end
function on_deprecated_call(name, alternatives)
if __warnings_hidden[name] then
@ -200,6 +214,21 @@ end
local __internal_locked = false
local default_compiler = {
module = {
execute = function(code, path, env)
local script, err = load(code, path)
if script == nil then
error(err)
end
if env then
script = setfenv(script, env)
end
return script
end
}
}
-- Load script with caching
--
-- path - script path `contentpack:filename`.
@ -211,6 +240,9 @@ function __load_script(path, nocache, env)
local is_internal = (packname == "res" or packname == "core")
and filename:find("modules/internal") == 1
local ext = path:match("%.([^:/\\]+)$")
local compiler = __compilers[ext] or default_compiler
nocache = nocache or is_internal
if is_internal and __internal_locked then
@ -225,13 +257,7 @@ function __load_script(path, nocache, env)
error("script '"..filename.."' not found in '"..packname.."'")
end
local script, err = load(file.read(path), path)
if script == nil then
error(err)
end
if env then
script = setfenv(script, env)
end
local script = compiler.module.execute(file.read(path), path, env)
local result = script()
if not nocache then
__cached_scripts[path] = script
@ -245,6 +271,9 @@ function __vc_lock_internal_modules()
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)
@ -277,6 +306,13 @@ function __scripts_cleanup(non_reset_packs)
__pack_envs[packname] = nil
::continue::
end
for ext, compiler in pairs(__compilers) do
if table.has(non_reset_packs, compiler.packid) then
goto continue
end
__compilers[ext] = nil
::continue::
end
end
function __vc__error(msg, frame, n, lastn)