diff options
author | Mike Pall <mike> | 2022-01-27 22:26:14 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2022-01-27 22:26:14 +0100 |
commit | 1d7b5029c5ba36870d25c67524034d452b761d27 (patch) | |
tree | da40633431980c80f6cb25014c12f8e7c017df04 | |
parent | b96d74621b6364c0e85199f13ca00b029341515c (diff) | |
parent | 9ebebc9b588dc1516c988b46d829445f505fdc1f (diff) | |
download | luajit-1d7b5029c5ba36870d25c67524034d452b761d27.tar.gz luajit-1d7b5029c5ba36870d25c67524034d452b761d27.tar.bz2 luajit-1d7b5029c5ba36870d25c67524034d452b761d27.zip |
Merge branch 'master' into v2.1
-rw-r--r-- | src/luajit.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/luajit.c b/src/luajit.c index 4e7a97d4..6dd64026 100644 --- a/src/luajit.c +++ b/src/luajit.c | |||
@@ -39,6 +39,7 @@ | |||
39 | 39 | ||
40 | static lua_State *globalL = NULL; | 40 | static lua_State *globalL = NULL; |
41 | static const char *progname = LUA_PROGNAME; | 41 | static const char *progname = LUA_PROGNAME; |
42 | static char *empty_argv[2] = { NULL, NULL }; | ||
42 | 43 | ||
43 | #if !LJ_TARGET_CONSOLE | 44 | #if !LJ_TARGET_CONSOLE |
44 | static void lstop(lua_State *L, lua_Debug *ar) | 45 | static void lstop(lua_State *L, lua_Debug *ar) |
@@ -78,9 +79,9 @@ static void print_usage(void) | |||
78 | fflush(stderr); | 79 | fflush(stderr); |
79 | } | 80 | } |
80 | 81 | ||
81 | static void l_message(const char *pname, const char *msg) | 82 | static void l_message(const char *msg) |
82 | { | 83 | { |
83 | if (pname) { fputs(pname, stderr); fputc(':', stderr); fputc(' ', stderr); } | 84 | if (progname) { fputs(progname, stderr); fputc(':', stderr); fputc(' ', stderr); } |
84 | fputs(msg, stderr); fputc('\n', stderr); | 85 | fputs(msg, stderr); fputc('\n', stderr); |
85 | fflush(stderr); | 86 | fflush(stderr); |
86 | } | 87 | } |
@@ -90,7 +91,7 @@ static int report(lua_State *L, int status) | |||
90 | if (status && !lua_isnil(L, -1)) { | 91 | if (status && !lua_isnil(L, -1)) { |
91 | const char *msg = lua_tostring(L, -1); | 92 | const char *msg = lua_tostring(L, -1); |
92 | if (msg == NULL) msg = "(error object is not a string)"; | 93 | if (msg == NULL) msg = "(error object is not a string)"; |
93 | l_message(progname, msg); | 94 | l_message(msg); |
94 | lua_pop(L, 1); | 95 | lua_pop(L, 1); |
95 | } | 96 | } |
96 | return status; | 97 | return status; |
@@ -256,9 +257,8 @@ static void dotty(lua_State *L) | |||
256 | lua_getglobal(L, "print"); | 257 | lua_getglobal(L, "print"); |
257 | lua_insert(L, 1); | 258 | lua_insert(L, 1); |
258 | if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) | 259 | if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) |
259 | l_message(progname, | 260 | l_message(lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)", |
260 | lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)", | 261 | lua_tostring(L, -1))); |
261 | lua_tostring(L, -1))); | ||
262 | } | 262 | } |
263 | } | 263 | } |
264 | lua_settop(L, 0); /* clear stack */ | 264 | lua_settop(L, 0); /* clear stack */ |
@@ -310,8 +310,7 @@ static int loadjitmodule(lua_State *L) | |||
310 | lua_getfield(L, -1, "start"); | 310 | lua_getfield(L, -1, "start"); |
311 | if (lua_isnil(L, -1)) { | 311 | if (lua_isnil(L, -1)) { |
312 | nomodule: | 312 | nomodule: |
313 | l_message(progname, | 313 | l_message("unknown luaJIT command or jit.* modules not installed"); |
314 | "unknown luaJIT command or jit.* modules not installed"); | ||
315 | return 1; | 314 | return 1; |
316 | } | 315 | } |
317 | lua_remove(L, -2); /* Drop module table. */ | 316 | lua_remove(L, -2); /* Drop module table. */ |
@@ -516,8 +515,6 @@ static int pmain(lua_State *L) | |||
516 | int argn; | 515 | int argn; |
517 | int flags = 0; | 516 | int flags = 0; |
518 | globalL = L; | 517 | globalL = L; |
519 | if (argv[0] && argv[0][0]) progname = argv[0]; | ||
520 | |||
521 | LUAJIT_VERSION_SYM(); /* Linker-enforced version check. */ | 518 | LUAJIT_VERSION_SYM(); /* Linker-enforced version check. */ |
522 | 519 | ||
523 | argn = collectargs(argv, &flags); | 520 | argn = collectargs(argv, &flags); |
@@ -572,9 +569,11 @@ static int pmain(lua_State *L) | |||
572 | int main(int argc, char **argv) | 569 | int main(int argc, char **argv) |
573 | { | 570 | { |
574 | int status; | 571 | 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(); | ||
576 | if (L == NULL) { | 575 | if (L == NULL) { |
577 | l_message(argv[0], "cannot create state: not enough memory"); | 576 | l_message("cannot create state: not enough memory"); |
578 | return EXIT_FAILURE; | 577 | return EXIT_FAILURE; |
579 | } | 578 | } |
580 | smain.argc = argc; | 579 | smain.argc = argc; |