From 913e1fe6b3f46ab6163067fab44fe2cc77363803 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sat, 12 Jul 2014 19:18:31 -0400 Subject: [PATCH] Make legacy table copy entries --- legacy.lua | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/legacy.lua b/legacy.lua index 01db69a..a67fbd4 100644 --- a/legacy.lua +++ b/legacy.lua @@ -111,31 +111,22 @@ HasOwner = areas.hasOwner -- This is entirely untested and may break in strange and new ways. if areas.legacy_table then - owner_defs = {} - setmetatable(owner_defs, { + owner_defs = setmetatable({}, { __index = function(table, key) local a = rawget(areas.areas, key) - if a then - a.x1 = a.pos1.x - a.y1 = a.pos1.y - a.z1 = a.pos1.z - a.x2 = a.pos2.x - a.y2 = a.pos2.y - a.z2 = a.pos2.z - a.pos1, a.pos2 = nil, nil - a.id = key - end - return a + if not a then return a end + local b = {} + for k, v in pairs(a) do b[k] = v end + b.x1, b.y1, b.z1 = b.pos1.x, b.pos1.y, b.pos1.z + b.x2, b.y1, b.z2 = b.pos2.x, b.pos2.y, b.pos2.z + b.pos1, b.pos2 = nil, nil + b.id = key + return b end, __newindex = function(table, key, value) local a = value - a.pos1, a.pos2 = {}, {} - a.pos1.x = a.x1 - a.pos1.y = a.y1 - a.pos1.z = a.z1 - a.pos2.x = a.x2 - a.pos2.y = a.y2 - a.pos2.z = a.z2 + a.pos1, a.pos2 = {x=a.x1, y=a.y1, z=a.z1}, + {x=a.x2, y=a.y2, z=a.z2} a.x1, a.y1, a.z1, a.x2, a.y2, a.z2 = nil, nil, nil, nil, nil, nil a.name = a.name or "unnamed"