Skip to content

Commit 1d7b502

Browse files
author
Mike Pall
committed
Merge branch 'master' into v2.1
2 parents b96d746 + 9ebebc9 commit 1d7b502

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/luajit.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
static lua_State *globalL = NULL;
4141
static const char *progname = LUA_PROGNAME;
42+
static char *empty_argv[2] = { NULL, NULL };
4243

4344
#if !LJ_TARGET_CONSOLE
4445
static void lstop(lua_State *L, lua_Debug *ar)
@@ -78,9 +79,9 @@ static void print_usage(void)
7879
fflush(stderr);
7980
}
8081

81-
static void l_message(const char *pname, const char *msg)
82+
static void l_message(const char *msg)
8283
{
83-
if (pname) { fputs(pname, stderr); fputc(':', stderr); fputc(' ', stderr); }
84+
if (progname) { fputs(progname, stderr); fputc(':', stderr); fputc(' ', stderr); }
8485
fputs(msg, stderr); fputc('\n', stderr);
8586
fflush(stderr);
8687
}
@@ -90,7 +91,7 @@ static int report(lua_State *L, int status)
9091
if (status && !lua_isnil(L, -1)) {
9192
const char *msg = lua_tostring(L, -1);
9293
if (msg == NULL) msg = "(error object is not a string)";
93-
l_message(progname, msg);
94+
l_message(msg);
9495
lua_pop(L, 1);
9596
}
9697
return status;
@@ -256,9 +257,8 @@ static void dotty(lua_State *L)
256257
lua_getglobal(L, "print");
257258
lua_insert(L, 1);
258259
if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
259-
l_message(progname,
260-
lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)",
261-
lua_tostring(L, -1)));
260+
l_message(lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)",
261+
lua_tostring(L, -1)));
262262
}
263263
}
264264
lua_settop(L, 0); /* clear stack */
@@ -310,8 +310,7 @@ static int loadjitmodule(lua_State *L)
310310
lua_getfield(L, -1, "start");
311311
if (lua_isnil(L, -1)) {
312312
nomodule:
313-
l_message(progname,
314-
"unknown luaJIT command or jit.* modules not installed");
313+
l_message("unknown luaJIT command or jit.* modules not installed");
315314
return 1;
316315
}
317316
lua_remove(L, -2); /* Drop module table. */
@@ -516,8 +515,6 @@ static int pmain(lua_State *L)
516515
int argn;
517516
int flags = 0;
518517
globalL = L;
519-
if (argv[0] && argv[0][0]) progname = argv[0];
520-
521518
LUAJIT_VERSION_SYM(); /* Linker-enforced version check. */
522519

523520
argn = collectargs(argv, &flags);
@@ -572,9 +569,11 @@ static int pmain(lua_State *L)
572569
int main(int argc, char **argv)
573570
{
574571
int status;
575-
lua_State *L = lua_open();
572+
lua_State *L;
573+
if (!argv[0]) argv = empty_argv; else if (argv[0][0]) progname = argv[0];
574+
L = lua_open();
576575
if (L == NULL) {
577-
l_message(argv[0], "cannot create state: not enough memory");
576+
l_message("cannot create state: not enough memory");
578577
return EXIT_FAILURE;
579578
}
580579
smain.argc = argc;

0 commit comments

Comments
 (0)