Unsilence builtin/strict.lua

This commit is contained in:
Lars Mueller
2021-01-17 18:19:46 +01:00
parent 1e10ab0270
commit a1bf8a104f
3 changed files with 10 additions and 7 deletions

View File

@ -1,5 +1,3 @@
-- Silence builtin/strict.lua
setmetatable(_G, {})
-- Lua version check
if _VERSION then
if _VERSION < "Lua 5" then

View File

@ -687,7 +687,7 @@ function colorspec:to_number()
return self.r * 0xFFFFFF + self.g * 0xFFFF + self.b * 0xFF + self.a
end
colorspec_to_colorstring = _G.minetest.colorspec_to_colorstring or function(spec)
colorspec_to_colorstring = rawget(_G, "minetest").colorspec_to_colorstring or function(spec)
return colorspec.from_any(spec):to_string()
end

13
mod.lua
View File

@ -14,9 +14,14 @@ end
function create_namespace(namespace_name, parent_namespace)
namespace_name = namespace_name or minetest.get_current_modname()
parent_namespace = parent_namespace or _G
local namespace = setmetatable({}, {__index = parent_namespace})
-- should use rawset if MT's strictness wasn't disabled in init.lua
parent_namespace[namespace_name] = namespace
local metatable = {__index = parent_namespace == _G and function(_, key) return rawget(_G, key) end or parent_namespace}
local namespace = {}
namespace = setmetatable(namespace, metatable)
if parent_namespace == _G then
rawset(parent_namespace, namespace_name, namespace)
else
parent_namespace[namespace_name] = namespace
end
return namespace
end
@ -26,7 +31,7 @@ function extend(modname, file)
file = modname
modname = minetest.get_current_modname()
end
include_env(get_resource(modname, file .. ".lua"), _G[modname])
include_env(get_resource(modname, file .. ".lua"), rawget(_G, modname))
end
-- runs main.lua in table env