summaryrefslogtreecommitdiff
path: root/library/lua
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-06-14 12:46:12 +0400
committerAlexander Gavrilov2012-06-14 12:46:12 +0400
commit7eb4fc19de542db0d3e271123f24773e0c8c481e (patch)
tree027f53970a8333eac7e33079c297c7b87754a333 /library/lua
parent2781723f7bf2bef87b7c6c5252aebd6392cbefbf (diff)
downloaddfhack-7eb4fc19de542db0d3e271123f24773e0c8c481e.tar.gz
dfhack-7eb4fc19de542db0d3e271123f24773e0c8c481e.tar.bz2
dfhack-7eb4fc19de542db0d3e271123f24773e0c8c481e.tar.xz
Make dfhack.run_script usable from other scripts, and document it.
Diffstat (limited to 'library/lua')
-rw-r--r--library/lua/dfhack.lua13
1 files changed, 9 insertions, 4 deletions
diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua
index 926600c0..4cdb4c95 100644
--- a/library/lua/dfhack.lua
+++ b/library/lua/dfhack.lua
@@ -273,19 +273,24 @@ end
-- Command scripts
-dfhack.scripts = dfhack.scripts or {}
+dfhack.internal.scripts = dfhack.internal.scripts or {}
-function dfhack.run_script(file,...)
- local env = dfhack.scripts[file]
+local scripts = dfhack.internal.scripts
+local hack_path = dfhack.getHackPath()
+
+function dfhack.run_script(name,...)
+ local key = string.lower(name)
+ local file = hack_path..'scripts/'..name..'.lua'
+ local env = scripts[key]
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
+ scripts[key] = env
return f(...)
end