diff options
author | Robin Gareus <robin@gareus.org> | 2020-03-26 21:53:28 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2020-03-26 21:55:04 +0100 |
commit | dbc7da0bc6167ba081848609b6e94dc8876da765 (patch) | |
tree | 865ef50abf473728c964764cdf2c21de51c7b741 /luasession | |
parent | e219a6cd1e786dd8a8daa6e6da28953ae3705fcb (diff) |
Allow to pass arguments to ardour-lua
This follows the same standard as lua-5.x commandline interpreter,
using "arg" as table, which is always present in the global namespace.
Diffstat (limited to 'luasession')
-rw-r--r-- | luasession/luasession.cc | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/luasession/luasession.cc b/luasession/luasession.cc index 6f11ab675e..1a6cfdcd1d 100644 --- a/luasession/luasession.cc +++ b/luasession/luasession.cc @@ -516,7 +516,7 @@ static void usage () { printf ("ardour-lua - interactive Ardour Lua interpreter.\n\n"); - printf ("Usage: ardour-lua [ OPTIONS ] [ file ]\n\n"); + printf ("Usage: ardour-lua [ OPTIONS ] [ file [args] ]\n\n"); printf ("Options:\n\ -h, --help display this help and exit\n\ -i, --interactive enter interactive mode after executing 'script'\n\ @@ -571,7 +571,18 @@ main (int argc, char** argv) init (); setup_lua (); - if (argc > optind) { + { + /* push arguments to script, use scoped LuaRef */ + lua_State* L = lua->getState (); + luabridge::LuaRef arg (luabridge::newTable (L)); + for (int i = 1; i < argc - optind; ++i) { + arg[i] = std::string (argv[i + optind]); + } + luabridge::push (L, arg); + lua_setglobal (L, "arg"); + } + + if (argc > optind && 0 != strcmp (argv[optind], "-")) { lua->do_file (argv[optind]); } else { interactive = true; |