diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-10 14:41:38 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-10 14:41:38 -0300 |
| commit | 6f6fd96e3bd2cc1f61291717aee9d89ea0180cd4 (patch) | |
| tree | 77247f6bb46460afa33749cedfc841f22089f785 /lbaselib.c | |
| parent | 35a6aad0d745d3acb9d5feb895f84a05ae8bf5ba (diff) | |
| download | lua-6f6fd96e3bd2cc1f61291717aee9d89ea0180cd4.tar.gz lua-6f6fd96e3bd2cc1f61291717aee9d89ea0180cd4.tar.bz2 lua-6f6fd96e3bd2cc1f61291717aee9d89ea0180cd4.zip | |
new type lua_KFunction + no more 'lua_getctx'
Diffstat (limited to 'lbaselib.c')
| -rw-r--r-- | lbaselib.c | 40 |
1 files changed, 15 insertions, 25 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.287 2014/05/16 18:54:01 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.288 2014/06/02 03:06:26 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 | */ |
| @@ -341,7 +341,8 @@ static int luaB_load (lua_State *L) { | |||
| 341 | /* }====================================================== */ | 341 | /* }====================================================== */ |
| 342 | 342 | ||
| 343 | 343 | ||
| 344 | static int dofilecont (lua_State *L) { | 344 | static int dofilecont (lua_State *L, int d1, int d2) { |
| 345 | (void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */ | ||
| 345 | return lua_gettop(L) - 1; | 346 | return lua_gettop(L) - 1; |
| 346 | } | 347 | } |
| 347 | 348 | ||
| @@ -352,7 +353,7 @@ static int luaB_dofile (lua_State *L) { | |||
| 352 | if (luaL_loadfile(L, fname) != LUA_OK) | 353 | if (luaL_loadfile(L, fname) != LUA_OK) |
| 353 | return lua_error(L); | 354 | return lua_error(L); |
| 354 | lua_callk(L, 0, LUA_MULTRET, 0, dofilecont); | 355 | lua_callk(L, 0, LUA_MULTRET, 0, dofilecont); |
| 355 | return dofilecont(L); | 356 | return dofilecont(L, 0, 0); |
| 356 | } | 357 | } |
| 357 | 358 | ||
| 358 | 359 | ||
| @@ -385,13 +386,14 @@ static int luaB_select (lua_State *L) { | |||
| 385 | 386 | ||
| 386 | 387 | ||
| 387 | /* | 388 | /* |
| 388 | ** Finishes a 'pcall' or 'xpcall'. Both functions already pushed a | 389 | ** Continuation function for 'pcall' and 'xpcall'. Both functions |
| 389 | ** 'true' before doing the call, so in case of sucess 'finishpcall' | 390 | ** already pushed a 'true' before doing the call, so in case of sucess |
| 390 | ** only has to return everything in the stack minus 'extra' values | 391 | ** 'finishpcall' only has to return everything in the stack minus |
| 391 | ** (where 'extra' is exactly the number of items to be ignored). | 392 | ** 'extra' values (where 'extra' is exactly the number of items to be |
| 393 | ** ignored). | ||
| 392 | */ | 394 | */ |
| 393 | static int finishpcall (lua_State *L, int ok, int extra) { | 395 | static int finishpcall (lua_State *L, int status, int extra) { |
| 394 | if (!ok) { /* error? */ | 396 | if (status != LUA_OK && status != LUA_YIELD) { /* error? */ |
| 395 | lua_pushboolean(L, 0); /* first result (false) */ | 397 | lua_pushboolean(L, 0); /* first result (false) */ |
| 396 | lua_pushvalue(L, -2); /* error message */ | 398 | lua_pushvalue(L, -2); /* error message */ |
| 397 | return 2; /* return false, msg */ | 399 | return 2; /* return false, msg */ |
| @@ -401,25 +403,13 @@ static int finishpcall (lua_State *L, int ok, int extra) { | |||
| 401 | } | 403 | } |
| 402 | 404 | ||
| 403 | 405 | ||
| 404 | /* | ||
| 405 | ** Continuation function for 'pcall' and 'xpcall': get appropriate | ||
| 406 | ** state through 'lua_getctx' and call 'finishpcall' to finish the | ||
| 407 | ** original function. | ||
| 408 | */ | ||
| 409 | static int pcallcont (lua_State *L) { | ||
| 410 | int extra; | ||
| 411 | int status = lua_getctx(L, &extra); | ||
| 412 | return finishpcall(L, (status == LUA_YIELD), extra); | ||
| 413 | } | ||
| 414 | |||
| 415 | |||
| 416 | static int luaB_pcall (lua_State *L) { | 406 | static int luaB_pcall (lua_State *L) { |
| 417 | int status; | 407 | int status; |
| 418 | luaL_checkany(L, 1); | 408 | luaL_checkany(L, 1); |
| 419 | lua_pushboolean(L, 1); /* first result if no errors */ | 409 | lua_pushboolean(L, 1); /* first result if no errors */ |
| 420 | lua_insert(L, 1); /* put it in place */ | 410 | lua_insert(L, 1); /* put it in place */ |
| 421 | status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont); | 411 | status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall); |
| 422 | return finishpcall(L, (status == LUA_OK), 0); | 412 | return finishpcall(L, status, 0); |
| 423 | } | 413 | } |
| 424 | 414 | ||
| 425 | 415 | ||
| @@ -435,8 +425,8 @@ static int luaB_xpcall (lua_State *L) { | |||
| 435 | lua_pushboolean(L, 1); /* first result */ | 425 | lua_pushboolean(L, 1); /* first result */ |
| 436 | lua_pushvalue(L, 1); /* function */ | 426 | lua_pushvalue(L, 1); /* function */ |
| 437 | lua_rotate(L, 3, 2); /* move them below function's arguments */ | 427 | lua_rotate(L, 3, 2); /* move them below function's arguments */ |
| 438 | status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, pcallcont); | 428 | status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall); |
| 439 | return finishpcall(L, (status == LUA_OK), 2); | 429 | return finishpcall(L, status, 2); |
| 440 | } | 430 | } |
| 441 | 431 | ||
| 442 | 432 | ||
