diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-06 16:05:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-06 16:05:10 -0300 |
commit | 71144e3ff0cb81bd9b8bb56d94dc76074c638c64 (patch) | |
tree | 8098675276d0640684898d4302ea98ae91e2c430 | |
parent | 0dbf0c5953a3d72deebc7e41840a0e73b46de8bc (diff) | |
download | lua-71144e3ff0cb81bd9b8bb56d94dc76074c638c64.tar.gz lua-71144e3ff0cb81bd9b8bb56d94dc76074c638c64.tar.bz2 lua-71144e3ff0cb81bd9b8bb56d94dc76074c638c64.zip |
errors `return' int, to avoid warnings
+ home-made `sprintf' (first version)
-rw-r--r-- | lapi.c | 5 | ||||
-rw-r--r-- | lauxlib.c | 63 | ||||
-rw-r--r-- | lauxlib.h | 10 | ||||
-rw-r--r-- | lbaselib.c | 41 | ||||
-rw-r--r-- | ldblib.c | 57 | ||||
-rw-r--r-- | liolib.c | 15 | ||||
-rw-r--r-- | lmathlib.c | 4 | ||||
-rw-r--r-- | lstrlib.c | 11 | ||||
-rw-r--r-- | ltests.c | 4 | ||||
-rw-r--r-- | lua.h | 4 |
10 files changed, 118 insertions, 96 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.187 2002/05/02 16:55:55 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.188 2002/05/06 15:51:41 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -641,11 +641,12 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
641 | */ | 641 | */ |
642 | 642 | ||
643 | 643 | ||
644 | LUA_API void lua_errorobj (lua_State *L) { | 644 | LUA_API int lua_errorobj (lua_State *L) { |
645 | lua_lock(L); | 645 | lua_lock(L); |
646 | api_checknelems(L, 1); | 646 | api_checknelems(L, 1); |
647 | luaD_errorobj(L, L->top - 1, LUA_ERRRUN); | 647 | luaD_errorobj(L, L->top - 1, LUA_ERRRUN); |
648 | lua_unlock(L); | 648 | lua_unlock(L); |
649 | return 0; /* to avoid warnings */ | ||
649 | } | 650 | } |
650 | 651 | ||
651 | 652 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.66 2002/04/16 12:00:02 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.67 2002/05/01 20:40:42 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 | */ |
@@ -30,23 +30,21 @@ LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { | |||
30 | } | 30 | } |
31 | 31 | ||
32 | 32 | ||
33 | LUALIB_API void luaL_argerror (lua_State *L, int narg, const char *extramsg) { | 33 | LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { |
34 | lua_Debug ar; | 34 | lua_Debug ar; |
35 | lua_getstack(L, 0, &ar); | 35 | lua_getstack(L, 0, &ar); |
36 | lua_getinfo(L, "n", &ar); | 36 | lua_getinfo(L, "n", &ar); |
37 | if (strcmp(ar.namewhat, "method") == 0) narg--; /* do not count `self' */ | 37 | if (strcmp(ar.namewhat, "method") == 0) narg--; /* do not count `self' */ |
38 | if (ar.name == NULL) | 38 | if (ar.name == NULL) |
39 | ar.name = "?"; | 39 | ar.name = "?"; |
40 | luaL_verror(L, "bad argument #%d to `%.50s' (%.100s)", | 40 | return luaL_verror(L, "bad argument #%d to `%s' (%s)", |
41 | narg, ar.name, extramsg); | 41 | narg, ar.name, extramsg); |
42 | } | 42 | } |
43 | 43 | ||
44 | 44 | ||
45 | LUALIB_API void luaL_typerror (lua_State *L, int narg, const char *tname) { | 45 | LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { |
46 | char buff[80]; | 46 | luaL_vstr(L, "%s expected, got %s", tname, lua_typename(L, lua_type(L,narg))); |
47 | sprintf(buff, "%.25s expected, got %.25s", tname, | 47 | return luaL_argerror(L, narg, lua_tostring(L, -1)); |
48 | lua_typename(L, lua_type(L,narg))); | ||
49 | luaL_argerror(L, narg, buff); | ||
50 | } | 48 | } |
51 | 49 | ||
52 | 50 | ||
@@ -57,11 +55,11 @@ static void tag_error (lua_State *L, int narg, int tag) { | |||
57 | 55 | ||
58 | LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *mes) { | 56 | LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *mes) { |
59 | if (!lua_checkstack(L, space)) | 57 | if (!lua_checkstack(L, space)) |
60 | luaL_verror(L, "stack overflow (%.30s)", mes); | 58 | luaL_verror(L, "stack overflow (%s)", mes); |
61 | } | 59 | } |
62 | 60 | ||
63 | 61 | ||
64 | LUALIB_API void luaL_check_type(lua_State *L, int narg, int t) { | 62 | LUALIB_API void luaL_check_type (lua_State *L, int narg, int t) { |
65 | if (lua_type(L, narg) != t) | 63 | if (lua_type(L, narg) != t) |
66 | tag_error(L, narg, t); | 64 | tag_error(L, narg, t); |
67 | } | 65 | } |
@@ -144,13 +142,48 @@ LUALIB_API void luaL_opennamedlib (lua_State *L, const char *libname, | |||
144 | } | 142 | } |
145 | 143 | ||
146 | 144 | ||
147 | LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...) { | 145 | static void vstr (lua_State *L, const char *fmt, va_list argp) { |
148 | char buff[500]; | 146 | luaL_Buffer b; |
147 | luaL_buffinit(L, &b); | ||
148 | for (;;) { | ||
149 | const char *e = strchr(fmt, '%'); | ||
150 | if (e == NULL) break; | ||
151 | luaL_addlstring(&b, fmt, e-fmt); | ||
152 | switch (*(e+1)) { | ||
153 | case 's': | ||
154 | luaL_addstring(&b, va_arg(argp, char *)); | ||
155 | break; | ||
156 | case 'd': | ||
157 | lua_pushnumber(L, va_arg(argp, int)); | ||
158 | luaL_addvalue (&b); | ||
159 | break; | ||
160 | case '%': | ||
161 | luaL_putchar(&b, '%'); | ||
162 | break; | ||
163 | default: | ||
164 | lua_error(L, "invalid format option"); | ||
165 | } | ||
166 | fmt = e+2; | ||
167 | } | ||
168 | luaL_addstring(&b, fmt); | ||
169 | luaL_pushresult(&b); | ||
170 | } | ||
171 | |||
172 | |||
173 | LUALIB_API void luaL_vstr (lua_State *L, const char *fmt, ...) { | ||
174 | va_list argp; | ||
175 | va_start(argp, fmt); | ||
176 | vstr(L, fmt, argp); | ||
177 | va_end(argp); | ||
178 | } | ||
179 | |||
180 | |||
181 | LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...) { | ||
149 | va_list argp; | 182 | va_list argp; |
150 | va_start(argp, fmt); | 183 | va_start(argp, fmt); |
151 | vsprintf(buff, fmt, argp); | 184 | vstr(L, fmt, argp); |
152 | va_end(argp); | 185 | va_end(argp); |
153 | lua_error(L, buff); | 186 | return lua_errorobj(L); |
154 | } | 187 | } |
155 | 188 | ||
156 | 189 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.h,v 1.44 2002/04/02 20:42:49 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.45 2002/05/01 20:40:42 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 | */ |
@@ -31,9 +31,8 @@ LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int nup); | |||
31 | LUALIB_API void luaL_opennamedlib (lua_State *L, const char *libname, | 31 | LUALIB_API void luaL_opennamedlib (lua_State *L, const char *libname, |
32 | const luaL_reg *l, int nup); | 32 | const luaL_reg *l, int nup); |
33 | LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event); | 33 | LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event); |
34 | LUALIB_API void luaL_typerror (lua_State *L, int narg, const char *tname); | 34 | LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname); |
35 | LUALIB_API void luaL_argerror (lua_State *L, int numarg, | 35 | LUALIB_API int luaL_argerror (lua_State *L, int numarg, const char *extramsg); |
36 | const char *extramsg); | ||
37 | LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, | 36 | LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, |
38 | size_t *len); | 37 | size_t *len); |
39 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, | 38 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, |
@@ -45,7 +44,8 @@ LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *msg); | |||
45 | LUALIB_API void luaL_check_type (lua_State *L, int narg, int t); | 44 | LUALIB_API void luaL_check_type (lua_State *L, int narg, int t); |
46 | LUALIB_API void luaL_check_any (lua_State *L, int narg); | 45 | LUALIB_API void luaL_check_any (lua_State *L, int narg); |
47 | 46 | ||
48 | LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...); | 47 | LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...); |
48 | LUALIB_API void luaL_vstr (lua_State *L, const char *fmt, ...); | ||
49 | LUALIB_API int luaL_findstring (const char *name, | 49 | LUALIB_API int luaL_findstring (const char *name, |
50 | const char *const list[]); | 50 | const char *const list[]); |
51 | 51 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.70 2002/05/01 20:40:42 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.71 2002/05/02 17:12:27 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 | */ |
@@ -43,9 +43,7 @@ static int luaB__ERRORMESSAGE (lua_State *L) { | |||
43 | if (lua_getstack(L, 1, &ar)) { | 43 | if (lua_getstack(L, 1, &ar)) { |
44 | lua_getinfo(L, "Sl", &ar); | 44 | lua_getinfo(L, "Sl", &ar); |
45 | if (ar.source && ar.currentline > 0) { | 45 | if (ar.source && ar.currentline > 0) { |
46 | char buff[100]; | 46 | luaL_vstr(L, "\n <%s: line %d>", ar.short_src, ar.currentline); |
47 | sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline); | ||
48 | lua_pushstring(L, buff); | ||
49 | lua_concat(L, 2); | 47 | lua_concat(L, 2); |
50 | } | 48 | } |
51 | } | 49 | } |
@@ -72,7 +70,7 @@ static int luaB_print (lua_State *L) { | |||
72 | lua_rawcall(L, 1, 1); | 70 | lua_rawcall(L, 1, 1); |
73 | s = lua_tostring(L, -1); /* get result */ | 71 | s = lua_tostring(L, -1); /* get result */ |
74 | if (s == NULL) | 72 | if (s == NULL) |
75 | luaL_verror(L, "`tostring' must return a string to `print'"); | 73 | return luaL_verror(L, "`tostring' must return a string to `print'"); |
76 | if (i>1) fputs("\t", stdout); | 74 | if (i>1) fputs("\t", stdout); |
77 | fputs(s, stdout); | 75 | fputs(s, stdout); |
78 | lua_pop(L, 1); /* pop result */ | 76 | lua_pop(L, 1); /* pop result */ |
@@ -112,8 +110,7 @@ static int luaB_tonumber (lua_State *L) { | |||
112 | 110 | ||
113 | static int luaB_error (lua_State *L) { | 111 | static int luaB_error (lua_State *L) { |
114 | lua_settop(L, 1); | 112 | lua_settop(L, 1); |
115 | lua_errorobj(L); | 113 | return lua_errorobj(L); |
116 | return 0; /* to avoid warnings */ | ||
117 | } | 114 | } |
118 | 115 | ||
119 | 116 | ||
@@ -242,7 +239,7 @@ static int luaB_loadfile (lua_State *L) { | |||
242 | static int luaB_assert (lua_State *L) { | 239 | static int luaB_assert (lua_State *L) { |
243 | luaL_check_any(L, 1); | 240 | luaL_check_any(L, 1); |
244 | if (!lua_toboolean(L, 1)) | 241 | if (!lua_toboolean(L, 1)) |
245 | luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, "")); | 242 | return luaL_verror(L, "assertion failed! %s", luaL_opt_string(L, 2, "")); |
246 | lua_settop(L, 1); | 243 | lua_settop(L, 1); |
247 | return 1; | 244 | return 1; |
248 | } | 245 | } |
@@ -335,6 +332,7 @@ static const char *getpath (lua_State *L) { | |||
335 | const char *path; | 332 | const char *path; |
336 | lua_getglobal(L, LUA_PATH); /* try global variable */ | 333 | lua_getglobal(L, LUA_PATH); /* try global variable */ |
337 | path = lua_tostring(L, -1); | 334 | path = lua_tostring(L, -1); |
335 | lua_pop(L, 1); | ||
338 | if (path) return path; | 336 | if (path) return path; |
339 | path = getenv(LUA_PATH); /* else try environment variable */ | 337 | path = getenv(LUA_PATH); /* else try environment variable */ |
340 | if (path) return path; | 338 | if (path) return path; |
@@ -342,7 +340,7 @@ static const char *getpath (lua_State *L) { | |||
342 | } | 340 | } |
343 | 341 | ||
344 | 342 | ||
345 | static const char *nextpath (lua_State *L, const char *path) { | 343 | static const char *pushnextpath (lua_State *L, const char *path) { |
346 | const char *l; | 344 | const char *l; |
347 | if (*path == '\0') return NULL; /* no more pathes */ | 345 | if (*path == '\0') return NULL; /* no more pathes */ |
348 | if (*path == LUA_PATH_SEP) path++; /* skip separator */ | 346 | if (*path == LUA_PATH_SEP) path++; /* skip separator */ |
@@ -353,7 +351,7 @@ static const char *nextpath (lua_State *L, const char *path) { | |||
353 | } | 351 | } |
354 | 352 | ||
355 | 353 | ||
356 | static void composename (lua_State *L) { | 354 | static void pushcomposename (lua_State *L) { |
357 | const char *path = lua_tostring(L, -1); | 355 | const char *path = lua_tostring(L, -1); |
358 | const char *wild = strchr(path, '?'); | 356 | const char *wild = strchr(path, '?'); |
359 | if (wild == NULL) return; /* no wild char; path is the file name */ | 357 | if (wild == NULL) return; /* no wild char; path is the file name */ |
@@ -372,35 +370,34 @@ static int luaB_require (lua_State *L) { | |||
372 | lua_pushvalue(L, 1); | 370 | lua_pushvalue(L, 1); |
373 | lua_setglobal(L, "_REQUIREDNAME"); | 371 | lua_setglobal(L, "_REQUIREDNAME"); |
374 | lua_getglobal(L, REQTAB); | 372 | lua_getglobal(L, REQTAB); |
375 | if (!lua_istable(L, 2)) luaL_verror(L, REQTAB " is not a table"); | 373 | if (!lua_istable(L, 2)) return luaL_verror(L, REQTAB " is not a table"); |
376 | path = getpath(L); | 374 | path = getpath(L); |
377 | lua_pushvalue(L, 1); /* check package's name in book-keeping table */ | 375 | lua_pushvalue(L, 1); /* check package's name in book-keeping table */ |
378 | lua_gettable(L, 2); | 376 | lua_gettable(L, 2); |
379 | if (!lua_isnil(L, -1)) /* is it there? */ | 377 | if (!lua_isnil(L, -1)) /* is it there? */ |
380 | return 0; /* package is already loaded */ | 378 | return 0; /* package is already loaded */ |
381 | else { /* must load it */ | 379 | else { /* must load it */ |
382 | while (status == LUA_ERRFILE && (path = nextpath(L, path)) != NULL) { | 380 | while (status == LUA_ERRFILE) { |
383 | composename(L); | 381 | lua_settop(L, 3); /* reset stack position */ |
382 | if ((path = pushnextpath(L, path)) == NULL) break; | ||
383 | pushcomposename(L); | ||
384 | status = lua_loadfile(L, lua_tostring(L, -1)); /* try to load it */ | 384 | status = lua_loadfile(L, lua_tostring(L, -1)); /* try to load it */ |
385 | if (status == 0) | ||
386 | status = lua_pcall(L, 0, 0, 0); | ||
387 | lua_settop(L, 3); /* pop string and eventual results from dofile */ | ||
388 | } | 385 | } |
389 | } | 386 | } |
390 | switch (status) { | 387 | switch (status) { |
391 | case 0: { | 388 | case 0: { |
389 | lua_rawcall(L, 0, 0); /* run loaded module */ | ||
392 | lua_pushvalue(L, 1); | 390 | lua_pushvalue(L, 1); |
393 | lua_pushboolean(L, 1); | 391 | lua_pushboolean(L, 1); |
394 | lua_settable(L, 2); /* mark it as loaded */ | 392 | lua_settable(L, 2); /* mark it as loaded */ |
395 | return 0; | 393 | return 0; |
396 | } | 394 | } |
397 | case LUA_ERRFILE: { /* file not found */ | 395 | case LUA_ERRFILE: { /* file not found */ |
398 | luaL_verror(L, "could not load package `%.20s' from path `%.200s'", | 396 | return luaL_verror(L, "could not load package `%s' from path `%s'", |
399 | lua_tostring(L, 1), lua_tostring(L, 3)); | 397 | lua_tostring(L, 1), getpath(L)); |
400 | } | 398 | } |
401 | default: { | 399 | default: { |
402 | luaL_verror(L, "error loading package"); | 400 | return luaL_verror(L, "error loading package\n%s", lua_tostring(L, -1)); |
403 | return 0; /* to avoid warnings */ | ||
404 | } | 401 | } |
405 | } | 402 | } |
406 | } | 403 | } |
@@ -445,7 +442,7 @@ static int luaB_resume (lua_State *L) { | |||
445 | lua_State *co = (lua_State *)lua_getfrombox(L, lua_upvalueindex(1)); | 442 | lua_State *co = (lua_State *)lua_getfrombox(L, lua_upvalueindex(1)); |
446 | lua_settop(L, 0); | 443 | lua_settop(L, 0); |
447 | if (lua_resume(L, co) != 0) | 444 | if (lua_resume(L, co) != 0) |
448 | lua_errorobj(L); | 445 | return lua_errorobj(L); |
449 | return lua_gettop(L); | 446 | return lua_gettop(L); |
450 | } | 447 | } |
451 | 448 | ||
@@ -466,7 +463,7 @@ static int luaB_coroutine (lua_State *L) { | |||
466 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, | 463 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, |
467 | "Lua function expected"); | 464 | "Lua function expected"); |
468 | NL = lua_newthread(L); | 465 | NL = lua_newthread(L); |
469 | if (NL == NULL) luaL_verror(L, "unable to create new thread"); | 466 | if (NL == NULL) return luaL_verror(L, "unable to create new thread"); |
470 | /* move function and arguments from L to NL */ | 467 | /* move function and arguments from L to NL */ |
471 | for (i=0; i<n; i++) { | 468 | for (i=0; i<n; i++) { |
472 | ref = lua_ref(L, 1); | 469 | ref = lua_ref(L, 1); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.48 2002/04/22 14:40:50 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.49 2002/05/01 20:40:42 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 | */ |
@@ -47,9 +47,9 @@ static int getinfo (lua_State *L) { | |||
47 | options = buff; | 47 | options = buff; |
48 | } | 48 | } |
49 | else | 49 | else |
50 | luaL_argerror(L, 1, "function or level expected"); | 50 | return luaL_argerror(L, 1, "function or level expected"); |
51 | if (!lua_getinfo(L, options, &ar)) | 51 | if (!lua_getinfo(L, options, &ar)) |
52 | luaL_argerror(L, 2, "invalid option"); | 52 | return luaL_argerror(L, 2, "invalid option"); |
53 | lua_newtable(L); | 53 | lua_newtable(L); |
54 | for (; *options; options++) { | 54 | for (; *options; options++) { |
55 | switch (*options) { | 55 | switch (*options) { |
@@ -85,7 +85,7 @@ static int getlocal (lua_State *L) { | |||
85 | lua_Debug ar; | 85 | lua_Debug ar; |
86 | const char *name; | 86 | const char *name; |
87 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ | 87 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ |
88 | luaL_argerror(L, 1, "level out of range"); | 88 | return luaL_argerror(L, 1, "level out of range"); |
89 | name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); | 89 | name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); |
90 | if (name) { | 90 | if (name) { |
91 | lua_pushstring(L, name); | 91 | lua_pushstring(L, name); |
@@ -102,7 +102,7 @@ static int getlocal (lua_State *L) { | |||
102 | static int setlocal (lua_State *L) { | 102 | static int setlocal (lua_State *L) { |
103 | lua_Debug ar; | 103 | lua_Debug ar; |
104 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ | 104 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ |
105 | luaL_argerror(L, 1, "level out of range"); | 105 | return luaL_argerror(L, 1, "level out of range"); |
106 | luaL_check_any(L, 3); | 106 | luaL_check_any(L, 3); |
107 | lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2))); | 107 | lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2))); |
108 | return 1; | 108 | return 1; |
@@ -187,20 +187,19 @@ static int errorfb (lua_State *L) { | |||
187 | int level = 1; /* skip level 0 (it's this function) */ | 187 | int level = 1; /* skip level 0 (it's this function) */ |
188 | int firstpart = 1; /* still before eventual `...' */ | 188 | int firstpart = 1; /* still before eventual `...' */ |
189 | lua_Debug ar; | 189 | lua_Debug ar; |
190 | luaL_Buffer b; | 190 | luaL_check_string(L, 1); |
191 | luaL_buffinit(L, &b); | 191 | lua_settop(L, 1); |
192 | luaL_addstring(&b, luaL_check_string(L, 1)); | 192 | lua_pushliteral(L, "\n"); |
193 | luaL_addstring(&b, "\n"); | ||
194 | while (lua_getstack(L, level++, &ar)) { | 193 | while (lua_getstack(L, level++, &ar)) { |
195 | char buff[120]; /* enough to fit following `sprintf's */ | 194 | char buff[10]; |
196 | if (level == 2) | 195 | if (level == 2) |
197 | luaL_addstring(&b, "stack traceback:\n"); | 196 | lua_pushliteral(L, "stack traceback:\n"); |
198 | else if (level > LEVELS1 && firstpart) { | 197 | else if (level > LEVELS1 && firstpart) { |
199 | /* no more than `LEVELS2' more levels? */ | 198 | /* no more than `LEVELS2' more levels? */ |
200 | if (!lua_getstack(L, level+LEVELS2, &ar)) | 199 | if (!lua_getstack(L, level+LEVELS2, &ar)) |
201 | level--; /* keep going */ | 200 | level--; /* keep going */ |
202 | else { | 201 | else { |
203 | luaL_addstring(&b, " ...\n"); /* too many levels */ | 202 | lua_pushliteral(L, " ...\n"); /* too many levels */ |
204 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ | 203 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ |
205 | level++; | 204 | level++; |
206 | } | 205 | } |
@@ -208,40 +207,34 @@ static int errorfb (lua_State *L) { | |||
208 | continue; | 207 | continue; |
209 | } | 208 | } |
210 | sprintf(buff, "%4d: ", level-1); | 209 | sprintf(buff, "%4d: ", level-1); |
211 | luaL_addstring(&b, buff); | 210 | lua_pushstring(L, buff); |
212 | lua_getinfo(L, "Snl", &ar); | 211 | lua_getinfo(L, "Snl", &ar); |
213 | switch (*ar.namewhat) { | 212 | switch (*ar.namewhat) { |
214 | case 'g': case 'l': /* global, local */ | 213 | case 'g': case 'l': /* global, local */ |
215 | sprintf(buff, "function `%.50s'", ar.name); | 214 | luaL_vstr(L, "function `%s'", ar.name); |
216 | break; | 215 | break; |
217 | case 'f': /* field */ | 216 | case 'f': /* field */ |
218 | sprintf(buff, "method `%.50s'", ar.name); | 217 | case 'm': /* method */ |
219 | break; | 218 | luaL_vstr(L, "method `%s'", ar.name); |
220 | case 't': /* tag method */ | ||
221 | sprintf(buff, "`%.50s' tag method", ar.name); | ||
222 | break; | 219 | break; |
223 | default: { | 220 | default: { |
224 | if (*ar.what == 'm') /* main? */ | 221 | if (*ar.what == 'm') /* main? */ |
225 | sprintf(buff, "main of %.70s", ar.short_src); | 222 | luaL_vstr(L, "main of %s", ar.short_src); |
226 | else if (*ar.what == 'C') /* C function? */ | 223 | else if (*ar.what == 'C') /* C function? */ |
227 | sprintf(buff, "%.70s", ar.short_src); | 224 | luaL_vstr(L, "%s", ar.short_src); |
228 | else | 225 | else |
229 | sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.short_src); | 226 | luaL_vstr(L, "function <%d:%s>", ar.linedefined, ar.short_src); |
230 | ar.source = NULL; /* do not print source again */ | 227 | ar.source = NULL; /* do not print source again */ |
231 | } | 228 | } |
232 | } | 229 | } |
233 | luaL_addstring(&b, buff); | 230 | if (ar.currentline > 0) |
234 | if (ar.currentline > 0) { | 231 | luaL_vstr(L, " at line %d", ar.currentline); |
235 | sprintf(buff, " at line %d", ar.currentline); | 232 | if (ar.source) |
236 | luaL_addstring(&b, buff); | 233 | luaL_vstr(L, " [%s]", ar.short_src); |
237 | } | 234 | lua_pushliteral(L, "\n"); |
238 | if (ar.source) { | 235 | lua_concat(L, lua_gettop(L)); |
239 | sprintf(buff, " [%.70s]", ar.short_src); | ||
240 | luaL_addstring(&b, buff); | ||
241 | } | ||
242 | luaL_addstring(&b, "\n"); | ||
243 | } | 236 | } |
244 | luaL_pushresult(&b); | 237 | lua_concat(L, lua_gettop(L)); |
245 | return 1; | 238 | return 1; |
246 | } | 239 | } |
247 | 240 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.3 2002/04/12 19:56:25 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.4 2002/05/02 17:12:27 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -257,7 +257,7 @@ static int g_read (lua_State *L, FILE *f, int first) { | |||
257 | else { | 257 | else { |
258 | const char *p = lua_tostring(L, n); | 258 | const char *p = lua_tostring(L, n); |
259 | if (!p || p[0] != '*') | 259 | if (!p || p[0] != '*') |
260 | luaL_verror(L, "invalid `read' option"); | 260 | return luaL_verror(L, "invalid `read' option"); |
261 | switch (p[1]) { | 261 | switch (p[1]) { |
262 | case 'n': /* number */ | 262 | case 'n': /* number */ |
263 | success = read_number(L, f); | 263 | success = read_number(L, f); |
@@ -270,11 +270,10 @@ static int g_read (lua_State *L, FILE *f, int first) { | |||
270 | success = 1; /* always success */ | 270 | success = 1; /* always success */ |
271 | break; | 271 | break; |
272 | case 'w': /* word */ | 272 | case 'w': /* word */ |
273 | luaL_verror(L, "obsolete option `*w'"); | 273 | return luaL_verror(L, "obsolete option `*w'"); |
274 | break; | 274 | break; |
275 | default: | 275 | default: |
276 | luaL_argerror(L, n, "invalid format"); | 276 | return luaL_argerror(L, n, "invalid format"); |
277 | success = 0; /* to avoid warnings */ | ||
278 | } | 277 | } |
279 | } | 278 | } |
280 | } | 279 | } |
@@ -430,7 +429,7 @@ static int io_rename (lua_State *L) { | |||
430 | static int io_tmpname (lua_State *L) { | 429 | static int io_tmpname (lua_State *L) { |
431 | char buff[L_tmpnam]; | 430 | char buff[L_tmpnam]; |
432 | if (tmpnam(buff) != buff) | 431 | if (tmpnam(buff) != buff) |
433 | luaL_verror(L, "unable to generate a unique filename"); | 432 | return luaL_verror(L, "unable to generate a unique filename"); |
434 | lua_pushstring(L, buff); | 433 | lua_pushstring(L, buff); |
435 | return 1; | 434 | return 1; |
436 | } | 435 | } |
@@ -471,7 +470,7 @@ static int getfield (lua_State *L, const char *key, int d) { | |||
471 | res = (int)(lua_tonumber(L, -1)); | 470 | res = (int)(lua_tonumber(L, -1)); |
472 | else { | 471 | else { |
473 | if (d == -2) | 472 | if (d == -2) |
474 | luaL_verror(L, "field `%.20s' missing in date table", key); | 473 | return luaL_verror(L, "field `%s' missing in date table", key); |
475 | res = d; | 474 | res = d; |
476 | } | 475 | } |
477 | lua_pop(L, 1); | 476 | lua_pop(L, 1); |
@@ -510,7 +509,7 @@ static int io_date (lua_State *L) { | |||
510 | if (strftime(b, sizeof(b), s, stm)) | 509 | if (strftime(b, sizeof(b), s, stm)) |
511 | lua_pushstring(L, b); | 510 | lua_pushstring(L, b); |
512 | else | 511 | else |
513 | luaL_verror(L, "invalid `date' format"); | 512 | return luaL_verror(L, "invalid `date' format"); |
514 | } | 513 | } |
515 | return 1; | 514 | return 1; |
516 | } | 515 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.43 2002/04/04 20:20:49 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.44 2002/05/02 17:12:27 roberto Exp roberto $ |
3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -187,7 +187,7 @@ static int math_random (lua_State *L) { | |||
187 | lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ | 187 | lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ |
188 | break; | 188 | break; |
189 | } | 189 | } |
190 | default: luaL_verror(L, "wrong number of arguments"); | 190 | default: return luaL_verror(L, "wrong number of arguments"); |
191 | } | 191 | } |
192 | return 1; | 192 | return 1; |
193 | } | 193 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.80 2002/04/02 20:41:59 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.81 2002/05/02 17:12:27 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -170,7 +170,7 @@ typedef struct MatchState { | |||
170 | static int check_capture (MatchState *ms, int l) { | 170 | static int check_capture (MatchState *ms, int l) { |
171 | l -= '1'; | 171 | l -= '1'; |
172 | if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) | 172 | if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) |
173 | luaL_verror(ms->L, "invalid capture index"); | 173 | return luaL_verror(ms->L, "invalid capture index"); |
174 | return l; | 174 | return l; |
175 | } | 175 | } |
176 | 176 | ||
@@ -179,8 +179,7 @@ static int capture_to_close (MatchState *ms) { | |||
179 | int level = ms->level; | 179 | int level = ms->level; |
180 | for (level--; level>=0; level--) | 180 | for (level--; level>=0; level--) |
181 | if (ms->capture[level].len == CAP_UNFINISHED) return level; | 181 | if (ms->capture[level].len == CAP_UNFINISHED) return level; |
182 | luaL_verror(ms->L, "invalid pattern capture"); | 182 | return luaL_verror(ms->L, "invalid pattern capture"); |
183 | return 0; /* to avoid warnings */ | ||
184 | } | 183 | } |
185 | 184 | ||
186 | 185 | ||
@@ -663,7 +662,7 @@ static int str_format (lua_State *L) { | |||
663 | char buff[MAX_ITEM]; /* to store the formatted item */ | 662 | char buff[MAX_ITEM]; /* to store the formatted item */ |
664 | int hasprecision = 0; | 663 | int hasprecision = 0; |
665 | if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$') | 664 | if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$') |
666 | luaL_verror(L, "obsolete `format' option (d$)"); | 665 | return luaL_verror(L, "obsolete `format' option (d$)"); |
667 | arg++; | 666 | arg++; |
668 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); | 667 | strfrmt = scanformat(L, strfrmt, form, &hasprecision); |
669 | switch (*strfrmt++) { | 668 | switch (*strfrmt++) { |
@@ -696,7 +695,7 @@ static int str_format (lua_State *L) { | |||
696 | } | 695 | } |
697 | } | 696 | } |
698 | default: /* also treat cases `pnLlh' */ | 697 | default: /* also treat cases `pnLlh' */ |
699 | luaL_verror(L, "invalid option in `format'"); | 698 | return luaL_verror(L, "invalid option in `format'"); |
700 | } | 699 | } |
701 | luaL_addlstring(&b, buff, strlen(buff)); | 700 | luaL_addlstring(&b, buff, strlen(buff)); |
702 | } | 701 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.118 2002/05/01 20:40:42 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.119 2002/05/02 13:06:20 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -639,7 +639,7 @@ static int testC (lua_State *L) { | |||
639 | else if EQ("type") { | 639 | else if EQ("type") { |
640 | lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); | 640 | lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); |
641 | } | 641 | } |
642 | else luaL_verror(L, "unknown instruction %.30s", buff); | 642 | else luaL_verror(L, "unknown instruction %s", buff); |
643 | } | 643 | } |
644 | return 0; | 644 | return 0; |
645 | } | 645 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.129 2002/05/01 20:40:42 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.130 2002/05/01 20:48:12 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
5 | ** e-mail: info@lua.org | 5 | ** e-mail: info@lua.org |
@@ -193,7 +193,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold); | |||
193 | ** miscellaneous functions | 193 | ** miscellaneous functions |
194 | */ | 194 | */ |
195 | 195 | ||
196 | LUA_API void lua_errorobj (lua_State *L); | 196 | LUA_API int lua_errorobj (lua_State *L); |
197 | 197 | ||
198 | LUA_API int lua_next (lua_State *L, int index); | 198 | LUA_API int lua_next (lua_State *L, int index); |
199 | LUA_API int lua_getn (lua_State *L, int index); | 199 | LUA_API int lua_getn (lua_State *L, int index); |