aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luajit.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/luajit.c b/src/luajit.c
index e723e522..cf4982a6 100644
--- a/src/luajit.c
+++ b/src/luajit.c
@@ -39,6 +39,7 @@
39 39
40static lua_State *globalL = NULL; 40static lua_State *globalL = NULL;
41static const char *progname = LUA_PROGNAME; 41static const char *progname = LUA_PROGNAME;
42static char *empty_argv[2] = { NULL, NULL };
42 43
43#if !LJ_TARGET_CONSOLE 44#if !LJ_TARGET_CONSOLE
44static void lstop(lua_State *L, lua_Debug *ar) 45static void lstop(lua_State *L, lua_Debug *ar)
@@ -79,9 +80,9 @@ static void print_usage(void)
79 fflush(stderr); 80 fflush(stderr);
80} 81}
81 82
82static void l_message(const char *pname, const char *msg) 83static void l_message(const char *msg)
83{ 84{
84 if (pname) fprintf(stderr, "%s: ", pname); 85 if (progname) fprintf(stderr, "%s: ", progname);
85 fprintf(stderr, "%s\n", msg); 86 fprintf(stderr, "%s\n", msg);
86 fflush(stderr); 87 fflush(stderr);
87} 88}
@@ -91,7 +92,7 @@ static int report(lua_State *L, int status)
91 if (status && !lua_isnil(L, -1)) { 92 if (status && !lua_isnil(L, -1)) {
92 const char *msg = lua_tostring(L, -1); 93 const char *msg = lua_tostring(L, -1);
93 if (msg == NULL) msg = "(error object is not a string)"; 94 if (msg == NULL) msg = "(error object is not a string)";
94 l_message(progname, msg); 95 l_message(msg);
95 lua_pop(L, 1); 96 lua_pop(L, 1);
96 } 97 }
97 return status; 98 return status;
@@ -264,9 +265,8 @@ static void dotty(lua_State *L)
264 lua_getglobal(L, "print"); 265 lua_getglobal(L, "print");
265 lua_insert(L, 1); 266 lua_insert(L, 1);
266 if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) 267 if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
267 l_message(progname, 268 l_message(lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)",
268 lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)", 269 lua_tostring(L, -1)));
269 lua_tostring(L, -1)));
270 } 270 }
271 } 271 }
272 lua_settop(L, 0); /* clear stack */ 272 lua_settop(L, 0); /* clear stack */
@@ -309,8 +309,7 @@ static int loadjitmodule(lua_State *L)
309 lua_getfield(L, -1, "start"); 309 lua_getfield(L, -1, "start");
310 if (lua_isnil(L, -1)) { 310 if (lua_isnil(L, -1)) {
311 nomodule: 311 nomodule:
312 l_message(progname, 312 l_message("unknown luaJIT command or jit.* modules not installed");
313 "unknown luaJIT command or jit.* modules not installed");
314 return 1; 313 return 1;
315 } 314 }
316 lua_remove(L, -2); /* Drop module table. */ 315 lua_remove(L, -2); /* Drop module table. */
@@ -514,7 +513,6 @@ static int pmain(lua_State *L)
514 int script; 513 int script;
515 int flags = 0; 514 int flags = 0;
516 globalL = L; 515 globalL = L;
517 if (argv[0] && argv[0][0]) progname = argv[0];
518 LUAJIT_VERSION_SYM(); /* linker-enforced version check */ 516 LUAJIT_VERSION_SYM(); /* linker-enforced version check */
519 script = collectargs(argv, &flags); 517 script = collectargs(argv, &flags);
520 if (script < 0) { /* invalid args? */ 518 if (script < 0) { /* invalid args? */
@@ -558,9 +556,11 @@ static int pmain(lua_State *L)
558int main(int argc, char **argv) 556int main(int argc, char **argv)
559{ 557{
560 int status; 558 int status;
561 lua_State *L = lua_open(); /* create state */ 559 lua_State *L;
560 if (!argv[0]) argv = empty_argv; else if (argv[0][0]) progname = argv[0];
561 L = lua_open(); /* create state */
562 if (L == NULL) { 562 if (L == NULL) {
563 l_message(argv[0], "cannot create state: not enough memory"); 563 l_message("cannot create state: not enough memory");
564 return EXIT_FAILURE; 564 return EXIT_FAILURE;
565 } 565 }
566 smain.argc = argc; 566 smain.argc = argc;