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 )
@@ -90,9 +91,9 @@ static void print_tools_usage(void)
90
91
fflush (stderr );
91
92
}
92
93
93
- static void l_message (const char * pname , const char * msg )
94
+ static void l_message (const char * msg )
94
95
{
95
- if (pname ) { fputs (pname , stderr ); fputc (':' , stderr ); fputc (' ' , stderr ); }
96
+ if (progname ) { fputs (progname , stderr ); fputc (':' , stderr ); fputc (' ' , stderr ); }
96
97
fputs (msg , stderr ); fputc ('\n' , stderr );
97
98
fflush (stderr );
98
99
}
@@ -102,7 +103,7 @@ static int report(lua_State *L, int status)
102
103
if (status && !lua_isnil (L , -1 )) {
103
104
const char * msg = lua_tostring (L , -1 );
104
105
if (msg == NULL ) msg = "(error object is not a string)" ;
105
- l_message (progname , msg );
106
+ l_message (msg );
106
107
lua_pop (L , 1 );
107
108
}
108
109
return status ;
@@ -267,9 +268,8 @@ static void dotty(lua_State *L)
267
268
lua_getglobal (L , "print" );
268
269
lua_insert (L , 1 );
269
270
if (lua_pcall (L , lua_gettop (L )- 1 , 0 , 0 ) != 0 )
270
- l_message (progname ,
271
- lua_pushfstring (L , "error calling " LUA_QL ("print" ) " (%s)" ,
272
- lua_tostring (L , -1 )));
271
+ l_message (lua_pushfstring (L , "error calling " LUA_QL ("print" ) " (%s)" ,
272
+ lua_tostring (L , -1 )));
273
273
}
274
274
}
275
275
lua_settop (L , 0 ); /* clear stack */
@@ -321,8 +321,7 @@ static int loadjitmodule(lua_State *L)
321
321
lua_getfield (L , -1 , "start" );
322
322
if (lua_isnil (L , -1 )) {
323
323
nomodule :
324
- l_message (progname ,
325
- "unknown luaJIT command or jit.* modules not installed" );
324
+ l_message ("unknown luaJIT command or jit.* modules not installed" );
326
325
return 1 ;
327
326
}
328
327
lua_remove (L , -2 ); /* Drop module table. */
@@ -382,7 +381,7 @@ static int runtoolcmd(lua_State *L, const char *tool_name)
382
381
if (msg ) {
383
382
if (!strncmp (msg , "module " , 7 ))
384
383
msg = "unknown luaJIT command or tools not installed" ;
385
- l_message (progname , msg );
384
+ l_message (msg );
386
385
}
387
386
return 1 ;
388
387
}
@@ -566,7 +565,6 @@ static int pmain(lua_State *L)
566
565
int argn ;
567
566
int flags = 0 ;
568
567
globalL = L ;
569
- if (argv [0 ] && argv [0 ][0 ]) progname = argv [0 ];
570
568
571
569
LUAJIT_VERSION_SYM (); /* Linker-enforced version check. */
572
570
@@ -622,9 +620,11 @@ static int pmain(lua_State *L)
622
620
int main (int argc , char * * argv )
623
621
{
624
622
int status ;
625
- lua_State * L = lua_open ();
623
+ lua_State * L ;
624
+ if (!argv [0 ]) argv = empty_argv ; else if (argv [0 ][0 ]) progname = argv [0 ];
625
+ L = lua_open (); /* create state */
626
626
if (L == NULL ) {
627
- l_message (argv [ 0 ], "cannot create state: not enough memory" );
627
+ l_message ("cannot create state: not enough memory" );
628
628
return EXIT_FAILURE ;
629
629
}
630
630
smain .argc = argc ;
0 commit comments