Add a variant of printall() that uses ipairs

develop
lethosor 2014-09-08 20:30:18 -04:00
parent c4d6c384ae
commit fadca0aef2
2 changed files with 16 additions and 1 deletions

@ -167,6 +167,15 @@ function printall(table)
end
end
function printall_ipairs(table)
local ok,f,t,k = pcall(ipairs,table)
if ok then
for k,v in f,t,k do
print(string.format("%-23s\t = %s",tostring(k),tostring(v)))
end
end
end
function copyall(table)
local rv = {}
for k,v in pairs(table) do rv[k] = v end
@ -305,6 +314,10 @@ function dfhack.interpreter(prompt,hfile,env)
print(table.unpack(data,2,data.n))
printall(data[2])
end,
['@'] = function(data)
print(table.unpack(data,2,data.n))
printall_ipairs(data[2])
end,
['='] = function(data)
for i=2,data.n do
local varname = '_'..vcnt

@ -23,7 +23,7 @@ elseif cmd=="--save" or cmd=="-s" then
elseif cmd~=nil then
-- Support some of the prefixes allowed by dfhack.interpreter
local prefix
if string.match(cmd, "^[~!]") then
if string.match(cmd, "^[~@!]") then
prefix = string.sub(cmd, 1, 1)
cmd = 'return '..string.sub(cmd, 2)
end
@ -39,6 +39,8 @@ elseif cmd~=nil then
print(table.unpack(rv,2,rv.n))
if prefix == '~' then
printall(rv[2])
elseif prefix == '@' then
printall_ipairs(rv[2])
end
end
else