diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-16 16:09:19 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-16 16:09:19 -0300 |
| commit | f53fd8d5f5f6c06afb191c5f579c75fcf607d52d (patch) | |
| tree | 0ef069545cb003c7eabc8812ec88fc918606b554 | |
| parent | 955def034814e96f5f8e42def2e47ca6817ef103 (diff) | |
| download | lua-f53fd8d5f5f6c06afb191c5f579c75fcf607d52d.tar.gz lua-f53fd8d5f5f6c06afb191c5f579c75fcf607d52d.tar.bz2 lua-f53fd8d5f5f6c06afb191c5f579c75fcf607d52d.zip | |
_ALERT is a private afair of lua.c
| -rw-r--r-- | lbaselib.c | 14 | ||||
| -rw-r--r-- | lua.c | 20 |
2 files changed, 15 insertions, 19 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.73 2002/05/13 13:10:58 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.74 2002/05/16 18:39:46 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -21,17 +21,6 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | /* | 23 | /* |
| 24 | ** If your system does not support `stderr', redefine this function, or | ||
| 25 | ** redefine _ERRORMESSAGE so that it won't need _ALERT. | ||
| 26 | */ | ||
| 27 | static int luaB__ALERT (lua_State *L) { | ||
| 28 | fputs(luaL_check_string(L, 1), stderr); | ||
| 29 | putc('\n', stderr); | ||
| 30 | return 0; | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | /* | ||
| 35 | ** If your system does not support `stdout', you can just remove this function. | 24 | ** If your system does not support `stdout', you can just remove this function. |
| 36 | ** If you need, you can define your own `print' function, following this | 25 | ** If you need, you can define your own `print' function, following this |
| 37 | ** model but changing `fputs' to put the strings at a proper place | 26 | ** model but changing `fputs' to put the strings at a proper place |
| @@ -385,7 +374,6 @@ static int luaB_require (lua_State *L) { | |||
| 385 | 374 | ||
| 386 | 375 | ||
| 387 | static const luaL_reg base_funcs[] = { | 376 | static const luaL_reg base_funcs[] = { |
| 388 | {LUA_ALERT, luaB__ALERT}, | ||
| 389 | {"error", luaB_error}, | 377 | {"error", luaB_error}, |
| 390 | {"metatable", luaB_metatable}, | 378 | {"metatable", luaB_metatable}, |
| 391 | {"globals", luaB_globals}, | 379 | {"globals", luaB_globals}, |
| @@ -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); |
