39
39
40
40
static lua_State * globalL = NULL ;
41
41
static const char * progname = LUA_PROGNAME ;
42
+ static char * empty_argv [2 ] = { NULL , NULL };
42
43
43
44
#if !LJ_TARGET_CONSOLE
44
45
static void lstop (lua_State * L , lua_Debug * ar )
@@ -78,9 +79,9 @@ static void print_usage(void)
78
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
85
fputs (msg , stderr ); fputc ('\n' , stderr );
85
86
fflush (stderr );
86
87
}
@@ -90,7 +91,7 @@ static int report(lua_State *L, int status)
90
91
if (status && !lua_isnil (L , -1 )) {
91
92
const char * msg = lua_tostring (L , -1 );
92
93
if (msg == NULL ) msg = "(error object is not a string)" ;
93
- l_message (progname , msg );
94
+ l_message (msg );
94
95
lua_pop (L , 1 );
95
96
}
96
97
return status ;
@@ -256,9 +257,8 @@ static void dotty(lua_State *L)
256
257
lua_getglobal (L , "print" );
257
258
lua_insert (L , 1 );
258
259
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 )));
262
262
}
263
263
}
264
264
lua_settop (L , 0 ); /* clear stack */
@@ -310,8 +310,7 @@ static int loadjitmodule(lua_State *L)
310
310
lua_getfield (L , -1 , "start" );
311
311
if (lua_isnil (L , -1 )) {
312
312
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" );
315
314
return 1 ;
316
315
}
317
316
lua_remove (L , -2 ); /* Drop module table. */
@@ -516,8 +515,6 @@ static int pmain(lua_State *L)
516
515
int argn ;
517
516
int flags = 0 ;
518
517
globalL = L ;
519
- if (argv [0 ] && argv [0 ][0 ]) progname = argv [0 ];
520
-
521
518
LUAJIT_VERSION_SYM (); /* Linker-enforced version check. */
522
519
523
520
argn = collectargs (argv , & flags );
@@ -572,9 +569,11 @@ static int pmain(lua_State *L)
572
569
int main (int argc , char * * argv )
573
570
{
574
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
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
577
return EXIT_FAILURE ;
579
578
}
580
579
smain .argc = argc ;
0 commit comments