diff options
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 31 |
1 files changed, 7 insertions, 24 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.208 2002/11/22 17:16:52 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.209 2002/11/22 18:01:46 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -378,35 +378,17 @@ LUA_API int lua_yield (lua_State *L, int nresults) { | |||
378 | } | 378 | } |
379 | 379 | ||
380 | 380 | ||
381 | /* | 381 | int luaD_pcall (lua_State *L, Pfunc func, void *u, |
382 | ** Execute a protected call. | 382 | ptrdiff_t old_top, ptrdiff_t ef) { |
383 | */ | ||
384 | struct CallS { /* data to `f_call' */ | ||
385 | StkId func; | ||
386 | int nresults; | ||
387 | }; | ||
388 | |||
389 | |||
390 | static void f_call (lua_State *L, void *ud) { | ||
391 | struct CallS *c = cast(struct CallS *, ud); | ||
392 | luaD_call(L, c->func, c->nresults); | ||
393 | } | ||
394 | |||
395 | |||
396 | int luaD_pcall (lua_State *L, int nargs, int nresults, ptrdiff_t errfunc) { | ||
397 | struct CallS c; | ||
398 | int status; | 383 | int status; |
399 | unsigned short oldnCcalls = L->nCcalls; | 384 | unsigned short oldnCcalls = L->nCcalls; |
400 | ptrdiff_t old_top = savestack(L, L->top); | ||
401 | ptrdiff_t old_ci = saveci(L, L->ci); | 385 | ptrdiff_t old_ci = saveci(L, L->ci); |
402 | lu_byte old_allowhooks = L->allowhook; | 386 | lu_byte old_allowhooks = L->allowhook; |
403 | ptrdiff_t old_errfunc = L->errfunc; | 387 | ptrdiff_t old_errfunc = L->errfunc; |
404 | L->errfunc = errfunc; | 388 | L->errfunc = ef; |
405 | c.func = L->top - (nargs+1); /* function to be called */ | 389 | status = luaD_rawrunprotected(L, func, u); |
406 | c.nresults = nresults; | ||
407 | status = luaD_rawrunprotected(L, &f_call, &c); | ||
408 | if (status != 0) { /* an error occurred? */ | 390 | if (status != 0) { /* an error occurred? */ |
409 | StkId oldtop = restorestack(L, old_top) - (nargs+1); | 391 | StkId oldtop = restorestack(L, old_top); |
410 | luaF_close(L, oldtop); /* close eventual pending closures */ | 392 | luaF_close(L, oldtop); /* close eventual pending closures */ |
411 | seterrorobj(L, status, oldtop); | 393 | seterrorobj(L, status, oldtop); |
412 | L->nCcalls = oldnCcalls; | 394 | L->nCcalls = oldnCcalls; |
@@ -420,6 +402,7 @@ int luaD_pcall (lua_State *L, int nargs, int nresults, ptrdiff_t errfunc) { | |||
420 | } | 402 | } |
421 | 403 | ||
422 | 404 | ||
405 | |||
423 | /* | 406 | /* |
424 | ** Execute a protected parser. | 407 | ** Execute a protected parser. |
425 | */ | 408 | */ |