From 9a4fd03e424d0341052b7053e610c060963d70b1 Mon Sep 17 00:00:00 2001 From: expwnent Date: Tue, 1 Jul 2014 01:38:56 -0400 Subject: [PATCH] added anonymous-script.lua so item/reaction-trigger commands do not have to make a file for every trigger for simple operations --- scripts/modtools/anonymous-script.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scripts/modtools/anonymous-script.lua diff --git a/scripts/modtools/anonymous-script.lua b/scripts/modtools/anonymous-script.lua new file mode 100644 index 000000000..eee42845e --- /dev/null +++ b/scripts/modtools/anonymous-script.lua @@ -0,0 +1,15 @@ +--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" + +local args = {...} + +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)) +