mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add loaders (WIP)
This commit is contained in:
parent
4b234eb661
commit
9ca809ff94
6 changed files with 100 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue