summaryrefslogtreecommitdiff
path: root/tex/context/base/l-table.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2007-09-10 21:31:00 +0200
committerHans Hagen <pragma@wxs.nl>2007-09-10 21:31:00 +0200
commit104ea1dae3d609aeb395e19658ad6ea7d4c85eea (patch)
tree9e0f83de78120bf8e227025ea69d4a94cbda83e4 /tex/context/base/l-table.lua
parentdeecfe09c774d4c2835f6999b2cdd9ca07e9bdae (diff)
downloadcontext-104ea1dae3d609aeb395e19658ad6ea7d4c85eea.tar.gz
stable 2007.09.10 21:31
Diffstat (limited to 'tex/context/base/l-table.lua')
-rw-r--r--tex/context/base/l-table.lua34
1 files changed, 20 insertions, 14 deletions
diff --git a/tex/context/base/l-table.lua b/tex/context/base/l-table.lua
index f68e29d23..e8f56ca09 100644
--- a/tex/context/base/l-table.lua
+++ b/tex/context/base/l-table.lua
@@ -90,11 +90,15 @@ if not table.fastcopy then
local new = { }
for k,v in pairs(old) do
if type(v) == "table" then
- new[k] = table.copy(v)
+ new[k] = table.fastcopy(v) -- was just table.copy
else
new[k] = v
end
end
+ local mt = getmetatable(old)
+ if mt then
+ setmetatable(new,mt)
+ end
return new
else
return { }
@@ -105,30 +109,32 @@ end
if not table.copy then
- function table.copy(t, _lookup_table) -- taken from lua wiki
- _lookup_table = _lookup_table or { }
+ function table.copy(t, tables) -- taken from lua wiki, slightly adapted
+ tables = tables or { }
local tcopy = {}
- if not _lookup_table[t] then
- _lookup_table[t] = tcopy
+ if not tables[t] then
+ tables[t] = tcopy
end
- for i,v in pairs(t) do
+ for i,v in pairs(t) do -- brrr, what happens with sparse indexed
if type(i) == "table" then
- if _lookup_table[i] then
- i = _lookup_table[i]
+ if tables[i] then
+ i = tables[i]
else
- i = table.copy(i, _lookup_table)
+ i = table.copy(i, tables)
end
end
if type(v) ~= "table" then
tcopy[i] = v
+ elseif tables[v] then
+ tcopy[i] = tables[v]
else
- if _lookup_table[v] then
- tcopy[i] = _lookup_table[v]
- else
- tcopy[i] = table.copy(v, _lookup_table)
- end
+ tcopy[i] = table.copy(v, tables)
end
end
+ local mt = getmetatable(t)
+ if mt then
+ setmetatable(tcopy,mt)
+ end
return tcopy
end