From c7b0c0a406e698be30b13fae7a0c670d0d502619 Mon Sep 17 00:00:00 2001 From: uramer Date: Mon, 30 Jan 2023 23:22:18 +0100 Subject: [PATCH] Protecd UI Content's metatable --- components/lua_ui/content.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/lua_ui/content.lua b/components/lua_ui/content.lua index 8c0e935bb9..650a15ecc6 100644 --- a/components/lua_ui/content.lua +++ b/components/lua_ui/content.lua @@ -6,7 +6,7 @@ M.new = function(source) result.__nameIndex = {} for i, v in ipairs(source) do if type(v) ~= 'table' then - error("Content can only contain tables") + error('Content can only contain tables') end result[i] = v if type(v.name) == 'string' then @@ -28,7 +28,7 @@ local function getIndexFromKey(self, key) if type(key) == 'string' then index = self.__nameIndex[key] if not index then - error("Unexpected content key:" .. key) + error('Unexpected content key:' .. key) end end validateIndex(self, index) @@ -130,6 +130,10 @@ M.__pairs = function(self) return next, self, 1 end 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 )" \ No newline at end of file