Prevent people from altering the special "empty package" value,

which is stored in wesnoth.package to prevent reloading loaded
packages just because they didn't return anything.

There's a special exception for accessing __tostring because ilua needs it.
This commit is contained in:
Celtic Minstrel 2017-05-05 13:08:54 -04:00
parent 87f750e3df
commit b045760cd5

View file

@ -1,6 +1,18 @@
-- Note: This file is loaded automatically by the engine.
local empty_pkg = {}
local mt = {
__index = function(self, k)
if k ~= "__tostring" then
error("Tried to access an empty package")
end
end,
__newindex = function()
error("Tried to access an empty package")
end,
__metatable = "empty package",
__tostring = function() return "{empty package}" end,
}
local empty_pkg = setmetatable({}, mt)
local function resolve_package(pkg_name)
if pkg_name[#pkg_name] == '/' then
@ -50,3 +62,5 @@ function wesnoth.require(pkg_name)
return pkg
end
end
return empty_pkg