mirror of
https://github.com/appgurueu/modlib.git
synced 2024-12-22 13:22:27 +01:00
Add basic minetest.mod.require
This commit is contained in:
parent
1bccb39142
commit
72ca08ed3a
@ -6,6 +6,16 @@ local Settings, _G, assert, dofile, error, getmetatable, ipairs, loadfile, loads
|
||||
local _ENV = {}
|
||||
setfenv(1, _ENV)
|
||||
|
||||
local loaded = {}
|
||||
function require(filename)
|
||||
local modname = minetest.get_current_modname()
|
||||
loaded[modname] = loaded[modname] or {}
|
||||
-- Minetest ensures that `/` works even on Windows (path normalization)
|
||||
loaded[modname][filename] = loaded[modname][filename] -- already loaded?
|
||||
or dofile(minetest.get_modpath(modname) .. "/" .. filename:gsub("%.", "/") .. ".lua")
|
||||
return loaded[modname][filename]
|
||||
end
|
||||
|
||||
function loadfile_exports(filename)
|
||||
local env = setmetatable({}, {__index = _G})
|
||||
local file = assert(loadfile(filename))
|
||||
|
Loading…
Reference in New Issue
Block a user