13
0

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.
This commit is contained in:
Robin Gareus 2020-03-26 21:53:28 +01:00
parent e219a6cd1e
commit dbc7da0bc6
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -516,7 +516,7 @@ static void
usage () usage ()
{ {
printf ("ardour-lua - interactive Ardour Lua interpreter.\n\n"); 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\ printf ("Options:\n\
-h, --help display this help and exit\n\ -h, --help display this help and exit\n\
-i, --interactive enter interactive mode after executing 'script'\n\ -i, --interactive enter interactive mode after executing 'script'\n\
@ -571,7 +571,18 @@ main (int argc, char** argv)
init (); init ();
setup_lua (); 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]); lua->do_file (argv[optind]);
} else { } else {
interactive = true; interactive = true;