2014-07-03 14:14:57 -06:00
--scripts/modtools/anonymous-script.lua
2014-06-30 23:38:56 -06:00
--author expwnent
--a tool for invoking simple lua scripts without putting them in a file first
2015-10-23 17:57:04 -06:00
--[[=begin
2014-06-30 23:38:56 -06:00
2015-10-23 17:57:04 -06:00
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 . Example ::
anonymous - script " print(args[1]) " arg1 arg2
# prints " arg1 "
= end ] ]
2014-06-30 23:38:56 -06:00
local args = { ... }
2014-07-03 14:14:57 -06:00
--automatically collect arguments to make the anonymous script more succinct
2015-02-02 03:21:13 -07:00
--load(ld,source,mode,env)
2014-06-30 23:38:56 -06:00
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 ) )