@@ -510,6 +510,30 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
510
510
}
511
511
512
512
513
+ /*
514
+ ** precall for C functions
515
+ */
516
+ l_sinline CallInfo * precallC (lua_State * L , StkId func , int nresults ,
517
+ lua_CFunction f ) {
518
+ int n ; /* number of returns */
519
+ CallInfo * ci ;
520
+ checkstackGCp (L , LUA_MINSTACK , func ); /* ensure minimum stack size */
521
+ L -> ci = ci = prepCallInfo (L , func , nresults , CIST_C ,
522
+ L -> top + LUA_MINSTACK );
523
+ lua_assert (ci -> top <= L -> stack_last );
524
+ if (l_unlikely (L -> hookmask & LUA_MASKCALL )) {
525
+ int narg = cast_int (L -> top - func ) - 1 ;
526
+ luaD_hook (L , LUA_HOOKCALL , -1 , 1 , narg );
527
+ }
528
+ lua_unlock (L );
529
+ n = (* f )(L ); /* do the actual call */
530
+ lua_lock (L );
531
+ api_checknelems (L , n );
532
+ luaD_poscall (L , ci , n );
533
+ return NULL ;
534
+ }
535
+
536
+
513
537
/*
514
538
** Prepares the call to a function (C or Lua). For C functions, also do
515
539
** the call. The function to be called is at '*func'. The arguments
@@ -519,32 +543,11 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,
519
543
** original function position.
520
544
*/
521
545
CallInfo * luaD_precall (lua_State * L , StkId func , int nresults ) {
522
- lua_CFunction f ;
523
- retry :
524
546
switch (ttypetag (s2v (func ))) {
525
547
case LUA_VCCL : /* C closure */
526
- f = clCvalue (s2v (func ))-> f ;
527
- goto Cfunc ;
548
+ return precallC (L , func , nresults , clCvalue (s2v (func ))-> f );
528
549
case LUA_VLCF : /* light C function */
529
- f = fvalue (s2v (func ));
530
- Cfunc : {
531
- int n ; /* number of returns */
532
- CallInfo * ci ;
533
- checkstackGCp (L , LUA_MINSTACK , func ); /* ensure minimum stack size */
534
- L -> ci = ci = prepCallInfo (L , func , nresults , CIST_C ,
535
- L -> top + LUA_MINSTACK );
536
- lua_assert (ci -> top <= L -> stack_last );
537
- if (l_unlikely (L -> hookmask & LUA_MASKCALL )) {
538
- int narg = cast_int (L -> top - func ) - 1 ;
539
- luaD_hook (L , LUA_HOOKCALL , -1 , 1 , narg );
540
- }
541
- lua_unlock (L );
542
- n = (* f )(L ); /* do the actual call */
543
- lua_lock (L );
544
- api_checknelems (L , n );
545
- luaD_poscall (L , ci , n );
546
- return NULL ;
547
- }
550
+ return precallC (L , func , nresults , fvalue (s2v (func )));
548
551
case LUA_VLCL : { /* Lua function */
549
552
CallInfo * ci ;
550
553
Proto * p = clLvalue (s2v (func ))-> p ;
@@ -561,7 +564,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
561
564
}
562
565
default : { /* not a function */
563
566
func = luaD_tryfuncTM (L , func ); /* try to get '__call' metamethod */
564
- goto retry ; /* try again with metamethod */
567
+ return luaD_precall ( L , func , nresults ); /* try again with metamethod */
565
568
}
566
569
}
567
570
}
0 commit comments