diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-15 15:57:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-15 15:57:44 -0300 |
commit | b7a0503c1d72603b8f7e480f2abecbc05348cb69 (patch) | |
tree | bfac646fea320f73abec2ee57a0c96a704452884 /lua.c | |
parent | 1c328a191a8b86b7ad601cb9a935f1da5373fdf7 (diff) | |
download | lua-b7a0503c1d72603b8f7e480f2abecbc05348cb69.tar.gz lua-b7a0503c1d72603b8f7e480f2abecbc05348cb69.tar.bz2 lua-b7a0503c1d72603b8f7e480f2abecbc05348cb69.zip |
new format for error messages
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.84 2002/04/23 14:59:22 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.85 2002/05/01 20:40:42 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 | */ |
@@ -71,7 +71,7 @@ static void report (int status) { | |||
71 | else { | 71 | else { |
72 | const char *msg = lua_tostring(L, -1); | 72 | const char *msg = lua_tostring(L, -1); |
73 | if (msg == NULL) msg = "(no message)"; | 73 | if (msg == NULL) msg = "(no message)"; |
74 | fprintf(stderr, "error: %s\n", msg); | 74 | fprintf(stderr, "%s\n", msg); |
75 | lua_pop(L, 1); | 75 | lua_pop(L, 1); |
76 | } | 76 | } |
77 | } | 77 | } |
@@ -152,8 +152,8 @@ static int file_input (const char *name) { | |||
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | static int dostring (const char *s) { | 155 | static int dostring (const char *s, const char *name) { |
156 | int status = lua_loadbuffer(L, s, strlen(s), s); | 156 | int status = lua_loadbuffer(L, s, strlen(s), name); |
157 | if (status == 0) status = lcall(1); | 157 | if (status == 0) status = lcall(1); |
158 | report(status); | 158 | report(status); |
159 | return status; | 159 | return status; |
@@ -198,7 +198,7 @@ static const char *get_prompt (int firstline) { | |||
198 | 198 | ||
199 | static int incomplete (int status) { | 199 | static int incomplete (int status) { |
200 | if (status == LUA_ERRSYNTAX && | 200 | if (status == LUA_ERRSYNTAX && |
201 | strstr(lua_tostring(L, -1), "last token read: `<eof>'") != NULL) { | 201 | strstr(lua_tostring(L, -1), "near `<eof>'") != NULL) { |
202 | lua_pop(L, 1); | 202 | lua_pop(L, 1); |
203 | return 1; | 203 | return 1; |
204 | } | 204 | } |
@@ -289,7 +289,7 @@ static int handle_argv (char *argv[], int *toclose) { | |||
289 | print_usage(); | 289 | print_usage(); |
290 | return EXIT_FAILURE; | 290 | return EXIT_FAILURE; |
291 | } | 291 | } |
292 | if (dostring(argv[i]) != 0) { | 292 | if (dostring(argv[i], "=prog. argument") != 0) { |
293 | fprintf(stderr, "%s: error running argument `%.99s'\n", | 293 | fprintf(stderr, "%s: error running argument `%.99s'\n", |
294 | LUA_PROGNAME, argv[i]); | 294 | LUA_PROGNAME, argv[i]); |
295 | return EXIT_FAILURE; | 295 | return EXIT_FAILURE; |
@@ -340,6 +340,16 @@ static void openstdlibs (lua_State *l) { | |||
340 | } | 340 | } |
341 | 341 | ||
342 | 342 | ||
343 | static int handle_luainit (void) { | ||
344 | const char *init = getenv("LUA_INIT"); | ||
345 | if (init == NULL) return 0; /* status OK */ | ||
346 | else if (init[0] == '@') | ||
347 | return file_input(init+1); | ||
348 | else | ||
349 | return dostring(init, "=LUA_INIT"); | ||
350 | } | ||
351 | |||
352 | |||
343 | int main (int argc, char *argv[]) { | 353 | int main (int argc, char *argv[]) { |
344 | int status; | 354 | int status; |
345 | int toclose = 0; | 355 | int toclose = 0; |
@@ -347,6 +357,8 @@ int main (int argc, char *argv[]) { | |||
347 | L = lua_open(); /* create state */ | 357 | L = lua_open(); /* create state */ |
348 | LUA_USERINIT(L); /* open libraries */ | 358 | LUA_USERINIT(L); /* open libraries */ |
349 | register_getargs(argv); /* create `getargs' function */ | 359 | register_getargs(argv); /* create `getargs' function */ |
360 | status = handle_luainit(); | ||
361 | if (status != 0) return status; | ||
350 | status = handle_argv(argv+1, &toclose); | 362 | status = handle_argv(argv+1, &toclose); |
351 | if (toclose) | 363 | if (toclose) |
352 | lua_close(L); | 364 | lua_close(L); |