diff options
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -449,12 +449,13 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { | |||
449 | 449 | ||
450 | /* | 450 | /* |
451 | ** Prepares the call to a function (C or Lua). For C functions, also do | 451 | ** Prepares the call to a function (C or Lua). For C functions, also do |
452 | ** the call. The function to be called is at '*func'. The arguments are | 452 | ** the call. The function to be called is at '*func'. The arguments |
453 | ** on the stack, right after the function. Returns true if the call was | 453 | ** are on the stack, right after the function. Returns the CallInfo |
454 | ** made (it was a C function). When returns true, all the results are | 454 | ** to be executed, if it was a Lua function. Otherwise (a C function) |
455 | ** on the stack, starting at the original function position. | 455 | ** returns NULL, with all the results on the stack, starting at the |
456 | ** original function position. | ||
456 | */ | 457 | */ |
457 | int luaD_precall (lua_State *L, StkId func, int nresults) { | 458 | CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { |
458 | lua_CFunction f; | 459 | lua_CFunction f; |
459 | retry: | 460 | retry: |
460 | switch (ttypetag(s2v(func))) { | 461 | switch (ttypetag(s2v(func))) { |
@@ -482,7 +483,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
482 | lua_lock(L); | 483 | lua_lock(L); |
483 | api_checknelems(L, n); | 484 | api_checknelems(L, n); |
484 | luaD_poscall(L, ci, n); | 485 | luaD_poscall(L, ci, n); |
485 | return 1; | 486 | return NULL; |
486 | } | 487 | } |
487 | case LUA_VLCL: { /* Lua function */ | 488 | case LUA_VLCL: { /* Lua function */ |
488 | CallInfo *ci; | 489 | CallInfo *ci; |
@@ -494,14 +495,13 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
494 | L->ci = ci = next_ci(L); | 495 | L->ci = ci = next_ci(L); |
495 | ci->nresults = nresults; | 496 | ci->nresults = nresults; |
496 | ci->u.l.savedpc = p->code; /* starting point */ | 497 | ci->u.l.savedpc = p->code; /* starting point */ |
497 | ci->callstatus = 0; | ||
498 | ci->top = func + 1 + fsize; | 498 | ci->top = func + 1 + fsize; |
499 | ci->func = func; | 499 | ci->func = func; |
500 | L->ci = ci; | 500 | L->ci = ci; |
501 | for (; narg < nfixparams; narg++) | 501 | for (; narg < nfixparams; narg++) |
502 | setnilvalue(s2v(L->top++)); /* complete missing arguments */ | 502 | setnilvalue(s2v(L->top++)); /* complete missing arguments */ |
503 | lua_assert(ci->top <= L->stack_last); | 503 | lua_assert(ci->top <= L->stack_last); |
504 | return 0; | 504 | return ci; |
505 | } | 505 | } |
506 | default: { /* not a function */ | 506 | default: { /* not a function */ |
507 | checkstackGCp(L, 1, func); /* space for metamethod */ | 507 | checkstackGCp(L, 1, func); /* space for metamethod */ |
@@ -518,11 +518,14 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
518 | ** increment number of non-yieldable calls). | 518 | ** increment number of non-yieldable calls). |
519 | */ | 519 | */ |
520 | static void docall (lua_State *L, StkId func, int nResults, int inc) { | 520 | static void docall (lua_State *L, StkId func, int nResults, int inc) { |
521 | CallInfo *ci; | ||
521 | L->nCcalls += inc; | 522 | L->nCcalls += inc; |
522 | if (getCcalls(L) >= LUAI_MAXCCALLS) | 523 | if (unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) |
523 | luaE_checkcstack(L); | 524 | luaE_checkcstack(L); |
524 | if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ | 525 | if ((ci = luaD_precall(L, func, nResults)) != NULL) { /* Lua function? */ |
525 | luaV_execute(L, L->ci); /* call it */ | 526 | ci->callstatus = CIST_FRESH; /* mark that it is a "fresh" execute */ |
527 | luaV_execute(L, ci); /* call it */ | ||
528 | } | ||
526 | L->nCcalls -= inc; | 529 | L->nCcalls -= inc; |
527 | } | 530 | } |
528 | 531 | ||