diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-11-07 16:19:13 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-11-07 16:19:13 -0200 |
| commit | c957b270d23941df8ca533dfbf4c9da672a429b4 (patch) | |
| tree | c556f944f02eb65f12b477069b1bdf5fb07674ea /lbuiltin.c | |
| parent | 92791b9dd651b439de85bd761b47c837b78414fd (diff) | |
| download | lua-c957b270d23941df8ca533dfbf4c9da672a429b4.tar.gz lua-c957b270d23941df8ca533dfbf4c9da672a429b4.tar.bz2 lua-c957b270d23941df8ca533dfbf4c9da672a429b4.zip | |
"call" now handles errors (instead of "dostring")
Diffstat (limited to '')
| -rw-r--r-- | lbuiltin.c | 49 |
1 files changed, 29 insertions, 20 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbuiltin.c,v 1.5 1997/10/24 17:17:24 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.6 1997/11/04 15:27:53 roberto Exp roberto $ |
| 3 | ** Built-in functions | 3 | ** Built-in functions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -126,18 +126,11 @@ static void foreach (void) | |||
| 126 | 126 | ||
| 127 | static void internaldostring (void) | 127 | static void internaldostring (void) |
| 128 | { | 128 | { |
| 129 | lua_Object err = lua_getparam(2); | 129 | if (lua_getparam(2) != LUA_NOOBJECT) |
| 130 | if (err != LUA_NOOBJECT) { /* set new error method */ | 130 | lua_error("invalid 2nd argument (probably obsolete code)"); |
| 131 | lua_pushobject(err); | ||
| 132 | err = lua_seterrormethod(); | ||
| 133 | } | ||
| 134 | if (lua_dostring(luaL_check_string(1)) == 0) | 131 | if (lua_dostring(luaL_check_string(1)) == 0) |
| 135 | if (luaA_passresults() == 0) | 132 | if (luaA_passresults() == 0) |
| 136 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ | 133 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ |
| 137 | if (err != LUA_NOOBJECT) { /* restore old error method */ | ||
| 138 | lua_pushobject(err); | ||
| 139 | lua_seterrormethod(); | ||
| 140 | } | ||
| 141 | } | 134 | } |
| 142 | 135 | ||
| 143 | 136 | ||
| @@ -259,32 +252,48 @@ static int getnarg (lua_Object table) | |||
| 259 | { | 252 | { |
| 260 | lua_Object temp; | 253 | lua_Object temp; |
| 261 | /* temp = table.n */ | 254 | /* temp = table.n */ |
| 262 | lua_pushobject(table); lua_pushstring("n"); temp = lua_gettable(); | 255 | lua_pushobject(table); lua_pushstring("n"); temp = lua_rawgettable(); |
| 263 | return (lua_isnumber(temp) ? lua_getnumber(temp) : MAX_WORD); | 256 | return (lua_isnumber(temp) ? lua_getnumber(temp) : MAX_WORD); |
| 264 | } | 257 | } |
| 265 | 258 | ||
| 266 | static void luaI_call (void) | 259 | static void luaI_call (void) |
| 267 | { | 260 | { |
| 268 | lua_Object f = functionarg(1); | 261 | lua_Object f = luaL_nonnullarg(1); |
| 269 | lua_Object arg = tablearg(2); | 262 | lua_Object arg = tablearg(2); |
| 270 | char *options = luaL_opt_string(3, ""); | 263 | char *options = luaL_opt_string(3, ""); |
| 264 | lua_Object err = lua_getparam(4); | ||
| 271 | int narg = getnarg(arg); | 265 | int narg = getnarg(arg); |
| 272 | int i; | 266 | int i, status; |
| 267 | if (err != LUA_NOOBJECT) { /* set new error method */ | ||
| 268 | lua_pushobject(err); | ||
| 269 | err = lua_seterrormethod(); | ||
| 270 | } | ||
| 273 | /* push arg[1...n] */ | 271 | /* push arg[1...n] */ |
| 274 | for (i=0; i<narg; i++) { | 272 | for (i=0; i<narg; i++) { |
| 275 | lua_Object temp; | 273 | lua_Object temp; |
| 276 | /* temp = arg[i+1] */ | 274 | /* temp = arg[i+1] */ |
| 277 | lua_pushobject(arg); lua_pushnumber(i+1); temp = lua_gettable(); | 275 | lua_pushobject(arg); lua_pushnumber(i+1); temp = lua_rawgettable(); |
| 278 | if (narg == MAX_WORD && lua_isnil(temp)) | 276 | if (narg == MAX_WORD && lua_isnil(temp)) |
| 279 | break; | 277 | break; |
| 280 | lua_pushobject(temp); | 278 | lua_pushobject(temp); |
| 281 | } | 279 | } |
| 282 | if (lua_callfunction(f)) | 280 | status = lua_callfunction(f); |
| 283 | lua_error(NULL); | 281 | if (err != LUA_NOOBJECT) { /* restore old error method */ |
| 284 | else if (strchr(options, 'p')) | 282 | lua_pushobject(err); |
| 285 | luaA_packresults(); | 283 | lua_seterrormethod(); |
| 286 | else | 284 | } |
| 287 | luaA_passresults(); | 285 | if (status != 0) { /* error in call? */ |
| 286 | if (strchr(options, 'x')) | ||
| 287 | return; /* return nil to signal the error */ | ||
| 288 | else | ||
| 289 | lua_error(NULL); | ||
| 290 | } | ||
| 291 | else { /* no errors */ | ||
| 292 | if (strchr(options, 'p')) | ||
| 293 | luaA_packresults(); | ||
| 294 | else | ||
| 295 | luaA_passresults(); | ||
| 296 | } | ||
| 288 | } | 297 | } |
| 289 | 298 | ||
| 290 | 299 | ||
