mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-07 12:54:00 +00:00
Protecd UI Content's metatable
This commit is contained in:
parent
259f104311
commit
c7b0c0a406
@ -6,7 +6,7 @@ M.new = function(source)
|
|||||||
result.__nameIndex = {}
|
result.__nameIndex = {}
|
||||||
for i, v in ipairs(source) do
|
for i, v in ipairs(source) do
|
||||||
if type(v) ~= 'table' then
|
if type(v) ~= 'table' then
|
||||||
error("Content can only contain tables")
|
error('Content can only contain tables')
|
||||||
end
|
end
|
||||||
result[i] = v
|
result[i] = v
|
||||||
if type(v.name) == 'string' then
|
if type(v.name) == 'string' then
|
||||||
@ -28,7 +28,7 @@ local function getIndexFromKey(self, key)
|
|||||||
if type(key) == 'string' then
|
if type(key) == 'string' then
|
||||||
index = self.__nameIndex[key]
|
index = self.__nameIndex[key]
|
||||||
if not index then
|
if not index then
|
||||||
error("Unexpected content key:" .. key)
|
error('Unexpected content key:' .. key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
validateIndex(self, index)
|
validateIndex(self, index)
|
||||||
@ -130,6 +130,10 @@ M.__pairs = function(self)
|
|||||||
return next, self, 1
|
return next, self, 1
|
||||||
end
|
end
|
||||||
M.__ipairs = M.__pairs
|
M.__ipairs = M.__pairs
|
||||||
|
M.__metatable = {}
|
||||||
|
|
||||||
|
assert(not pcall(function() setmetatable(M.new({}), {}) end), 'Metatable is not protected')
|
||||||
|
assert(getmetatable(M.new) ~= M, 'Metatable is not protected')
|
||||||
|
|
||||||
return M
|
return M
|
||||||
)"
|
)"
|
Loading…
Reference in New Issue
Block a user