diff options
Diffstat (limited to 'lua.c')
| -rw-r--r-- | lua.c | 20 |
1 files changed, 14 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.85 2002/05/01 20:40:42 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.86 2002/05/15 18:57:44 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -69,9 +69,9 @@ static void laction (int i) { | |||
| 69 | static void report (int status) { | 69 | static void report (int status) { |
| 70 | if (status == 0) return; | 70 | if (status == 0) return; |
| 71 | else { | 71 | else { |
| 72 | const char *msg = lua_tostring(L, -1); | 72 | lua_getglobal(L, "_ALERT"); |
| 73 | if (msg == NULL) msg = "(no message)"; | 73 | lua_pushvalue(L, -2); |
| 74 | fprintf(stderr, "%s\n", msg); | 74 | lua_pcall(L, 1, 0, 0); |
| 75 | lua_pop(L, 1); | 75 | lua_pop(L, 1); |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| @@ -137,6 +137,13 @@ static void getargs (char *argv[]) { | |||
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | 139 | ||
| 140 | static int l_alert (lua_State *l) { | ||
| 141 | fputs(luaL_check_string(l, 1), stderr); | ||
| 142 | putc('\n', stderr); | ||
| 143 | return 0; | ||
| 144 | } | ||
| 145 | |||
| 146 | |||
| 140 | static int l_getargs (lua_State *l) { | 147 | static int l_getargs (lua_State *l) { |
| 141 | char **argv = (char **)lua_touserdata(l, lua_upvalueindex(1)); | 148 | char **argv = (char **)lua_touserdata(l, lua_upvalueindex(1)); |
| 142 | getargs(argv); | 149 | getargs(argv); |
| @@ -323,10 +330,11 @@ static int handle_argv (char *argv[], int *toclose) { | |||
| 323 | } | 330 | } |
| 324 | 331 | ||
| 325 | 332 | ||
| 326 | static void register_getargs (char *argv[]) { | 333 | static void register_own (char *argv[]) { |
| 327 | lua_pushudataval(L, argv); | 334 | lua_pushudataval(L, argv); |
| 328 | lua_pushcclosure(L, l_getargs, 1); | 335 | lua_pushcclosure(L, l_getargs, 1); |
| 329 | lua_setglobal(L, "getargs"); | 336 | lua_setglobal(L, "getargs"); |
| 337 | lua_register(L, "_ALERT", l_alert); | ||
| 330 | } | 338 | } |
| 331 | 339 | ||
| 332 | 340 | ||
| @@ -356,7 +364,7 @@ int main (int argc, char *argv[]) { | |||
| 356 | (void)argc; /* to avoid warnings */ | 364 | (void)argc; /* to avoid warnings */ |
| 357 | L = lua_open(); /* create state */ | 365 | L = lua_open(); /* create state */ |
| 358 | LUA_USERINIT(L); /* open libraries */ | 366 | LUA_USERINIT(L); /* open libraries */ |
| 359 | register_getargs(argv); /* create `getargs' function */ | 367 | register_own(argv); /* create own function */ |
| 360 | status = handle_luainit(); | 368 | status = handle_luainit(); |
| 361 | if (status != 0) return status; | 369 | if (status != 0) return status; |
| 362 | status = handle_argv(argv+1, &toclose); | 370 | status = handle_argv(argv+1, &toclose); |
