summaryrefslogtreecommitdiff
path: root/library/lua
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-05-04 19:47:18 +0400
committerAlexander Gavrilov2012-05-04 19:47:18 +0400
commitd4d6349f48d01b31f59f94238d6656e3b5d08508 (patch)
tree43e47bbb5bab970825ff217ddbc16e21a3711033 /library/lua
parent5afe2ca0020404d46ad3de840030a7b9e186b059 (diff)
downloaddfhack-d4d6349f48d01b31f59f94238d6656e3b5d08508.tar.gz
dfhack-d4d6349f48d01b31f59f94238d6656e3b5d08508.tar.bz2
dfhack-d4d6349f48d01b31f59f94238d6656e3b5d08508.tar.xz
Expose builtin commands to dfhack-run, and add lua script support.
Move builtin command implementation to Core methods, and fall back to hack/scripts/*.lua for otherwise unrecognized commands.
Diffstat (limited to 'library/lua')
-rw-r--r--library/lua/dfhack.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua
index c4c994d2..c0ba6437 100644
--- a/library/lua/dfhack.lua
+++ b/library/lua/dfhack.lua
@@ -269,5 +269,23 @@ function dfhack.interpreter(prompt,hfile,env)
return true
end
+-- Command scripts
+
+dfhack.scripts = dfhack.scripts or {}
+
+function dfhack.run_script(file,...)
+ local env = dfhack.scripts[file]
+ if env == nil then
+ env = {}
+ setmetatable(env, { __index = base_env })
+ dfhack.scripts[file] = env
+ end
+ local f,perr = loadfile(file, 't', env)
+ if f == nil then
+ error(perr)
+ end
+ return f(...)
+end
+
-- Feed the table back to the require() mechanism.
return dfhack