summaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-16 16:09:19 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-16 16:09:19 -0300
commitf53fd8d5f5f6c06afb191c5f579c75fcf607d52d (patch)
tree0ef069545cb003c7eabc8812ec88fc918606b554 /lua.c
parent955def034814e96f5f8e42def2e47ca6817ef103 (diff)
downloadlua-f53fd8d5f5f6c06afb191c5f579c75fcf607d52d.tar.gz
lua-f53fd8d5f5f6c06afb191c5f579c75fcf607d52d.tar.bz2
lua-f53fd8d5f5f6c06afb191c5f579c75fcf607d52d.zip
_ALERT is a private afair of lua.c
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/lua.c b/lua.c
index 344b3a02..7bc2866a 100644
--- a/lua.c
+++ b/lua.c
@@ -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) {
69static void report (int status) { 69static 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
140static int l_alert (lua_State *l) {
141 fputs(luaL_check_string(l, 1), stderr);
142 putc('\n', stderr);
143 return 0;
144}
145
146
140static int l_getargs (lua_State *l) { 147static 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
326static void register_getargs (char *argv[]) { 333static 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);