diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-02-18 17:18:41 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-02-18 17:18:41 -0200 |
commit | 4274738e81ad12923c2ae5c769b3350c36cf1505 (patch) | |
tree | 995af0a432f0e6a7b2b42f085c8b7ee6f21b4804 | |
parent | 0d7d559dcc4291c2df5106ec121a43239b1faa91 (diff) | |
download | lua-4274738e81ad12923c2ae5c769b3350c36cf1505.tar.gz lua-4274738e81ad12923c2ae5c769b3350c36cf1505.tar.bz2 lua-4274738e81ad12923c2ae5c769b3350c36cf1505.zip |
new macro 'luai_writestringerror'
-rw-r--r-- | lauxlib.c | 4 | ||||
-rw-r--r-- | ldblib.c | 10 | ||||
-rw-r--r-- | lua.c | 19 | ||||
-rw-r--r-- | luaconf.h | 10 |
4 files changed, 25 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.197 2010/01/21 16:49:21 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.198 2010/02/11 15:52:50 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -739,7 +739,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { | |||
739 | 739 | ||
740 | 740 | ||
741 | static int panic (lua_State *L) { | 741 | static int panic (lua_State *L) { |
742 | fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", | 742 | luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n", |
743 | lua_tostring(L, -1)); | 743 | lua_tostring(L, -1)); |
744 | return 0; /* return to Lua to abort */ | 744 | return 0; /* return to Lua to abort */ |
745 | } | 745 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.118 2009/11/25 15:27:51 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.119 2010/01/06 14:42:35 roberto Exp roberto $ |
3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -339,15 +339,13 @@ static int db_gethook (lua_State *L) { | |||
339 | static int db_debug (lua_State *L) { | 339 | static int db_debug (lua_State *L) { |
340 | for (;;) { | 340 | for (;;) { |
341 | char buffer[250]; | 341 | char buffer[250]; |
342 | fputs("lua_debug> ", stderr); | 342 | luai_writestringerror("%s", "lua_debug> "); |
343 | if (fgets(buffer, sizeof(buffer), stdin) == 0 || | 343 | if (fgets(buffer, sizeof(buffer), stdin) == 0 || |
344 | strcmp(buffer, "cont\n") == 0) | 344 | strcmp(buffer, "cont\n") == 0) |
345 | return 0; | 345 | return 0; |
346 | if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || | 346 | if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || |
347 | lua_pcall(L, 0, 0, 0)) { | 347 | lua_pcall(L, 0, 0, 0)) |
348 | fputs(lua_tostring(L, -1), stderr); | 348 | luai_writestringerror("%s\n", lua_tostring(L, -1)); |
349 | fputs("\n", stderr); | ||
350 | } | ||
351 | lua_settop(L, 0); /* remove eventual returns */ | 349 | lua_settop(L, 0); /* remove eventual returns */ |
352 | } | 350 | } |
353 | } | 351 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.185 2010/02/09 11:58:57 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.186 2010/02/11 17:12:27 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 | */ |
@@ -103,11 +103,14 @@ static void laction (int i) { | |||
103 | 103 | ||
104 | 104 | ||
105 | static void print_usage (const char *badoption) { | 105 | static void print_usage (const char *badoption) { |
106 | if (badoption[1] == 'e' || badoption[1] == 'l') | 106 | if (badoption[1] == 'e' || badoption[1] == 'l') { |
107 | fprintf(stderr, "%s: '%s' needs argument\n", progname, badoption); | 107 | luai_writestringerror("%s: ", progname); |
108 | else | 108 | luai_writestringerror("'%s' needs argument\n", badoption); |
109 | fprintf(stderr, "%s: unrecognized option '%s'\n", progname, badoption); | 109 | } else { |
110 | fprintf(stderr, | 110 | luai_writestringerror("%s: ", progname); |
111 | luai_writestringerror("unrecognized option '%s'\n", badoption); | ||
112 | } | ||
113 | luai_writestringerror( | ||
111 | "usage: %s [options] [script [args]]\n" | 114 | "usage: %s [options] [script [args]]\n" |
112 | "Available options are:\n" | 115 | "Available options are:\n" |
113 | " -e stat execute string " LUA_QL("stat") "\n" | 116 | " -e stat execute string " LUA_QL("stat") "\n" |
@@ -122,8 +125,8 @@ static void print_usage (const char *badoption) { | |||
122 | 125 | ||
123 | 126 | ||
124 | static void l_message (const char *pname, const char *msg) { | 127 | static void l_message (const char *pname, const char *msg) { |
125 | if (pname) fprintf(stderr, "%s: ", pname); | 128 | if (pname) luai_writestringerror("%s: ", pname); |
126 | fprintf(stderr, "%s\n", msg); | 129 | luai_writestringerror("%s\n", msg); |
127 | } | 130 | } |
128 | 131 | ||
129 | 132 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.131 2010/01/21 16:31:24 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.132 2010/01/21 16:49:21 roberto Exp roberto $ |
3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -192,10 +192,16 @@ | |||
192 | 192 | ||
193 | /* | 193 | /* |
194 | @@ luai_writestring defines how 'print' prints its results. | 194 | @@ luai_writestring defines how 'print' prints its results. |
195 | ** CHANGE it if your system does not have a useful stdout. | ||
196 | */ | 195 | */ |
196 | #include <stdio.h> | ||
197 | #define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout) | 197 | #define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout) |
198 | 198 | ||
199 | /* | ||
200 | @@ luai_writestringerror defines how to print error messages. | ||
201 | ** (A format string with one argument is enough for Lua...) | ||
202 | */ | ||
203 | #define luai_writestringerror(s,p) fprintf(stderr, (s), (p)) | ||
204 | |||
199 | 205 | ||
200 | 206 | ||
201 | 207 | ||