forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanonymous-script.lua
More file actions
33 lines (25 loc) · 1.02 KB
/
Copy pathanonymous-script.lua
File metadata and controls
33 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
--scripts/modtools/anonymous-script.lua
--author expwnent
--a tool for invoking simple lua scripts without putting them in a file first
--anonymous-script "print(args[1])" arg1 arg2
--# prints "arg1"
--[[
BEGIN_DOCS
.. _scripts/modtools/anonymous-script:
modtools/anonymous-script
=========================
This allows running a short simple Lua script passed as an argument instead of
running a script from a file. This is useful when you want to do something too
complicated to make with the existing modtools, but too simple to be worth its
own script file.
END_DOCS
]]
local args = {...}
--automatically collect arguments to make the anonymous script more succinct
--load(ld,source,mode,env)
local f,err = load('local args = {...}; ' .. args[1], '=(anonymous lua script)') --,'=(lua command)', 't')
if err then
error(err)
end
--we don't care about the result even if they return something for some reason: we just want to ensure its side-effects happen and print appropriate error messages
dfhack.safecall(f,table.unpack(args,2))