diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index 207c5545a..47577dd0c 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -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 diff --git a/scripts/lua.lua b/scripts/lua.lua index 6c31e67aa..a4a5dd22f 100644 --- a/scripts/lua.lua +++ b/scripts/lua.lua @@ -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