|
@@ -39,6 +39,7 @@
|
|
|
|
|
|
static lua_State *globalL = NULL;
|
|
|
static const char *progname = LUA_PROGNAME;
|
|
|
+static char *empty_argv[2] = { NULL, NULL };
|
|
|
|
|
|
#if !LJ_TARGET_CONSOLE
|
|
|
static void lstop(lua_State *L, lua_Debug *ar)
|
|
@@ -78,9 +79,9 @@ static void print_usage(void)
|
|
|
fflush(stderr);
|
|
|
}
|
|
|
|
|
|
-static void l_message(const char *pname, const char *msg)
|
|
|
+static void l_message(const char *msg)
|
|
|
{
|
|
|
- if (pname) { fputs(pname, stderr); fputc(':', stderr); fputc(' ', stderr); }
|
|
|
+ if (progname) { fputs(progname, stderr); fputc(':', stderr); fputc(' ', stderr); }
|
|
|
fputs(msg, stderr); fputc('\n', stderr);
|
|
|
fflush(stderr);
|
|
|
}
|
|
@@ -90,7 +91,7 @@ static int report(lua_State *L, int status)
|
|
|
if (status && !lua_isnil(L, -1)) {
|
|
|
const char *msg = lua_tostring(L, -1);
|
|
|
if (msg == NULL) msg = "(error object is not a string)";
|
|
|
- l_message(progname, msg);
|
|
|
+ l_message(msg);
|
|
|
lua_pop(L, 1);
|
|
|
}
|
|
|
return status;
|
|
@@ -256,9 +257,8 @@ static void dotty(lua_State *L)
|
|
|
lua_getglobal(L, "print");
|
|
|
lua_insert(L, 1);
|
|
|
if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
|
|
|
- l_message(progname,
|
|
|
- lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)",
|
|
|
- lua_tostring(L, -1)));
|
|
|
+ l_message(lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)",
|
|
|
+ lua_tostring(L, -1)));
|
|
|
}
|
|
|
}
|
|
|
lua_settop(L, 0); /* clear stack */
|
|
@@ -310,8 +310,7 @@ static int loadjitmodule(lua_State *L)
|
|
|
lua_getfield(L, -1, "start");
|
|
|
if (lua_isnil(L, -1)) {
|
|
|
nomodule:
|
|
|
- l_message(progname,
|
|
|
- "unknown luaJIT command or jit.* modules not installed");
|
|
|
+ l_message("unknown luaJIT command or jit.* modules not installed");
|
|
|
return 1;
|
|
|
}
|
|
|
lua_remove(L, -2); /* Drop module table. */
|
|
@@ -516,8 +515,6 @@ static int pmain(lua_State *L)
|
|
|
int argn;
|
|
|
int flags = 0;
|
|
|
globalL = L;
|
|
|
- if (argv[0] && argv[0][0]) progname = argv[0];
|
|
|
-
|
|
|
LUAJIT_VERSION_SYM(); /* Linker-enforced version check. */
|
|
|
|
|
|
argn = collectargs(argv, &flags);
|
|
@@ -572,9 +569,11 @@ static int pmain(lua_State *L)
|
|
|
int main(int argc, char **argv)
|
|
|
{
|
|
|
int status;
|
|
|
- lua_State *L = lua_open();
|
|
|
+ lua_State *L;
|
|
|
+ if (!argv[0]) argv = empty_argv; else if (argv[0][0]) progname = argv[0];
|
|
|
+ L = lua_open();
|
|
|
if (L == NULL) {
|
|
|
- l_message(argv[0], "cannot create state: not enough memory");
|
|
|
+ l_message("cannot create state: not enough memory");
|
|
|
return EXIT_FAILURE;
|
|
|
}
|
|
|
smain.argc = argc;
|