aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2012-06-06 21:33:56 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2012-06-06 21:33:56 -0400
commitf5d2813319d7ad84270607a083e8000694541724 (patch)
treeb4c0471d87febdb51272fc07757498a19cca9f5d
parent0ba47873ec725db8f4ba83bac2c33664ea8fd8c1 (diff)
downloadtextadept-f5d2813319d7ad84270607a083e8000694541724.tar.gz
textadept-f5d2813319d7ad84270607a083e8000694541724.zip
Check for `args` and `args.process()` in single instance; src/textadept.c
-rw-r--r--src/textadept.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/textadept.c b/src/textadept.c
index b8a1ea5b..4772121e 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -205,15 +205,20 @@ static int a_command_line(GApplication *app, GApplicationCommandLine *cmdline,
int argc = 0;
char **argv = g_application_command_line_get_arguments(cmdline, &argc);
if (argc > 1) {
- lua_getglobal(lua, "args"), lua_getfield(lua, -1, "process");
- 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
+ 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
}