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:
parent
87f750e3df
commit
b045760cd5
1 changed files with 15 additions and 1 deletions
|
@ -1,6 +1,18 @@
|
||||||
-- Note: This file is loaded automatically by the engine.
|
-- 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)
|
local function resolve_package(pkg_name)
|
||||||
if pkg_name[#pkg_name] == '/' then
|
if pkg_name[#pkg_name] == '/' then
|
||||||
|
@ -50,3 +62,5 @@ function wesnoth.require(pkg_name)
|
||||||
return pkg
|
return pkg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return empty_pkg
|
||||||
|
|
Loading…
Add table
Reference in a new issue