diff options
| author | Alexander Gavrilov | 2012-04-29 21:07:39 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-04-29 21:07:39 +0400 |
| commit | 2303a25bdefab30bea67f32d27d35e5002448e8a (patch) | |
| tree | d5f8ac14a823a504ad64ae30cc0fa2515f410485 /library/lua | |
| parent | 9c94b7c1e748743309dae75ec95e374f26624d5f (diff) | |
| download | dfhack-2303a25bdefab30bea67f32d27d35e5002448e8a.tar.gz dfhack-2303a25bdefab30bea67f32d27d35e5002448e8a.tar.bz2 dfhack-2303a25bdefab30bea67f32d27d35e5002448e8a.tar.xz | |
Implement unconstructed building instance creation and linking into world.
For more flexibility, the base api is split into 3 phases:
alloc, setSize, and construct. No support for non-actual
buildings like stockpiles and activity zones at the moment.
Diffstat (limited to 'library/lua')
| -rw-r--r-- | library/lua/dfhack.lua | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index aedd460b..6915cbb8 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -199,6 +199,25 @@ function dfhack.interpreter(prompt,hfile,env) local t_prompt = nil local vcnt = 1 + local pfix_handlers = { + ['!'] = function(data) + print(table.unpack(data,2,data.n)) + end, + ['~'] = function(data) + print(table.unpack(data,2,data.n)) + printall(data[2]) + end, + ['='] = function(data) + for i=2,data.n do + local varname = '_'..vcnt + prompt_env[varname] = data[i] + dfhack.print(varname..' = ') + safecall(print, data[i]) + vcnt = vcnt + 1 + end + end + } + setmetatable(prompt_env, { __index = env or _G }) while true do @@ -209,7 +228,7 @@ function dfhack.interpreter(prompt,hfile,env) elseif cmdline ~= '' then local pfix = string.sub(cmdline,1,1) - if not t_prompt and (pfix == '!' or pfix == '=') then + if not t_prompt and pfix_handlers[pfix] then cmdline = 'return '..string.sub(cmdline,2) else pfix = nil @@ -236,18 +255,7 @@ function dfhack.interpreter(prompt,hfile,env) if data[1] and data.n > 1 then prompt_env._ = data[2] - - if pfix == '!' then - safecall(print, table.unpack(data,2,data.n)) - else - for i=2,data.n do - local varname = '_'..vcnt - prompt_env[varname] = data[i] - dfhack.print(varname..' = ') - safecall(print, data[i]) - vcnt = vcnt + 1 - end - end + safecall(pfix_handlers[pfix], data) end end end |
