Bugfix:tables inside the Panel metatable were shared between panels as references and not as copies

master
Zughy 2020-07-27 01:54:50 +02:00
parent 497d5e3788
commit fac2e279d4
1 changed files with 5 additions and 3 deletions

View File

@ -34,9 +34,10 @@ Panel = {
function Panel:new(def)
local panel = {}
local metapanel = clone_table(Panel)
setmetatable(panel, self)
self.__index = self
setmetatable(panel, metapanel)
metapanel.__index = metapanel
if def.position then
panel.background_def.position = def.position
@ -206,8 +207,9 @@ function clone_table(orig)
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = orig_value
copy[clone_table(orig_key)] = clone_table(orig_value)
end
setmetatable(copy, clone_table(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end