diff options
-rw-r--r-- | core/args.lua | 9 | ||||
-rw-r--r-- | src/textadept.c | 21 |
2 files changed, 8 insertions, 22 deletions
diff --git a/core/args.lua b/core/args.lua index 1a96d2ec..8b478aa9 100644 --- a/core/args.lua +++ b/core/args.lua @@ -36,7 +36,6 @@ function M.register(short, long, narg, f, description) switches[short], switches[long] = t, t end ---- -- Processes command line argument table *arg*, handling switches previously -- defined using `args.register()` and treating unrecognized arguments as -- filenames to open. @@ -44,8 +43,7 @@ end -- @param arg Argument table. -- @see register -- @see _G.events --- @name process -function M.process(arg) +local function process(arg) local no_args = true local i = 1 while i <= #arg do @@ -64,6 +62,8 @@ function M.process(arg) end if no_args then events.emit(events.ARG_NONE) end end +events.connect(events.INITIALIZED, function() if arg then process(arg) end end) +events.connect('cmd_line', process) -- undocumented, single-instance event -- Shows all registered command line switches on the command line. local function show_help() @@ -98,7 +98,4 @@ _G._USERHOME = userhome M.register('-u', '--userhome', 1, function() end, 'Sets alternate _USERHOME') M.register('-f', '--force', 0, function() end, 'Forces unique instance') -events.connect(events.INITIALIZED, - function() if arg then M.process(arg) end end) - return M diff --git a/src/textadept.c b/src/textadept.c index 8bc8c2bf..a3e4b4ee 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -273,22 +273,11 @@ static int a_command_line(GApplication*_, GApplicationCommandLine *cmdline, int argc = 0; char **argv = g_application_command_line_get_arguments(cmdline, &argc); if (argc > 1) { - lua_getglobal(lua, "args"); - if (lua_istable(lua, -1)) { - lua_getfield(lua, -1, "process"); - if (lua_isfunction(lua, -1)) { - lua_newtable(lua); - const char *cwd = g_application_command_line_get_cwd(cmdline); - lua_pushstring(lua, cwd ? cwd : ""), lua_rawseti(lua, -2, -1); - for (int i = 0; i < argc; i++) - lua_pushstring(lua, argv[i]), lua_rawseti(lua, -2, i); - if (lua_pcall(lua, 1, 0, 0) != LUA_OK) { - lL_event(lua, "error", LUA_TSTRING, lua_tostring(lua, -1), -1); - lua_pop(lua, 1); // error message - } - } else lua_pop(lua, 1); // non-function - } - lua_pop(lua, 1); // args + lua_newtable(lua); + const char *cwd = g_application_command_line_get_cwd(cmdline); + lua_pushstring(lua, cwd ? cwd : ""), lua_rawseti(lua, -2, -1); + while (--argc) lua_pushstring(lua, argv[argc]), lua_rawseti(lua, -2, argc); + lL_event(lua, "cmd_line", LUA_TTABLE, luaL_ref(lua, LUA_REGISTRYINDEX), -1); } g_strfreev(argv); return (gtk_window_present(GTK_WINDOW(window)), 0); |