mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-26 09:13:53 +01:00
Minetest module: Remove _G index, add lazy loading
This commit is contained in:
parent
93f9e3adb1
commit
90614006ba
69
minetest.lua
69
minetest.lua
@ -1,14 +1,59 @@
|
|||||||
local _ENV = setmetatable({}, {__index = _G})
|
local _ENV = {}
|
||||||
local function load(filename)
|
|
||||||
assert(loadfile(modlib.mod.get_resource(modlib.modname, "minetest", filename .. ".lua")))(_ENV)
|
local components = {}
|
||||||
|
for _, value in pairs{
|
||||||
|
"luon",
|
||||||
|
"raycast",
|
||||||
|
"schematic",
|
||||||
|
"colorspec"
|
||||||
|
} do
|
||||||
|
components[value] = value
|
||||||
end
|
end
|
||||||
-- minetest/gametime.lua is forceloaded in init.lua
|
for filename, comps in pairs{
|
||||||
load"misc"
|
misc = {
|
||||||
load"collisionboxes"
|
"max_wear",
|
||||||
load"liquid"
|
"override",
|
||||||
load"raycast"
|
"register_globalstep",
|
||||||
load"wielditem_change"
|
"form_listeners",
|
||||||
load"colorspec"
|
"register_form_listener",
|
||||||
load"schematic"
|
"texture_modifier_inventorycube",
|
||||||
load"luon"
|
"get_node_inventory_image",
|
||||||
|
"check_player_privs",
|
||||||
|
"decode_base64",
|
||||||
|
"objects_inside_radius",
|
||||||
|
"objects_inside_area",
|
||||||
|
"nodename_matcher"
|
||||||
|
},
|
||||||
|
liquid = {
|
||||||
|
"liquid_level_max",
|
||||||
|
"get_liquid_corner_levels",
|
||||||
|
"flowing_downwards",
|
||||||
|
"get_liquid_flow_direction"
|
||||||
|
},
|
||||||
|
wielditem_change = {
|
||||||
|
"players",
|
||||||
|
"registered_on_wielditem_changes",
|
||||||
|
"register_on_wielditem_change"
|
||||||
|
},
|
||||||
|
colorspec = {
|
||||||
|
"named_colors",
|
||||||
|
"colorspec_to_colorstring"
|
||||||
|
},
|
||||||
|
collisionboxes = {
|
||||||
|
"get_node_collisionboxes"
|
||||||
|
}
|
||||||
|
} do
|
||||||
|
for _, component in pairs(comps) do
|
||||||
|
components[component] = filename
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setmetatable(_ENV, {__index = function(_ENV, name)
|
||||||
|
local filename = components[name]
|
||||||
|
if filename then
|
||||||
|
assert(loadfile(modlib.mod.get_resource(modlib.modname, "minetest", filename .. ".lua")))(_ENV)
|
||||||
|
return rawget(_ENV, name)
|
||||||
|
end
|
||||||
|
end})
|
||||||
|
|
||||||
return _ENV
|
return _ENV
|
Loading…
Reference in New Issue
Block a user