1*088332b5SXin Li /* 2*088332b5SXin Li ** $Id: lapi.h $ 3*088332b5SXin Li ** Auxiliary functions from Lua API 4*088332b5SXin Li ** See Copyright Notice in lua.h 5*088332b5SXin Li */ 6*088332b5SXin Li 7*088332b5SXin Li #ifndef lapi_h 8*088332b5SXin Li #define lapi_h 9*088332b5SXin Li 10*088332b5SXin Li 11*088332b5SXin Li #include "llimits.h" 12*088332b5SXin Li #include "lstate.h" 13*088332b5SXin Li 14*088332b5SXin Li 15*088332b5SXin Li /* Increments 'L->top', checking for stack overflows */ 16*088332b5SXin Li #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 17*088332b5SXin Li "stack overflow");} 18*088332b5SXin Li 19*088332b5SXin Li 20*088332b5SXin Li /* 21*088332b5SXin Li ** If a call returns too many multiple returns, the callee may not have 22*088332b5SXin Li ** stack space to accommodate all results. In this case, this macro 23*088332b5SXin Li ** increases its stack space ('L->ci->top'). 24*088332b5SXin Li */ 25*088332b5SXin Li #define adjustresults(L,nres) \ 26*088332b5SXin Li { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 27*088332b5SXin Li 28*088332b5SXin Li 29*088332b5SXin Li /* Ensure the stack has at least 'n' elements */ 30*088332b5SXin Li #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 31*088332b5SXin Li "not enough elements in the stack") 32*088332b5SXin Li 33*088332b5SXin Li 34*088332b5SXin Li /* 35*088332b5SXin Li ** To reduce the overhead of returning from C functions, the presence of 36*088332b5SXin Li ** to-be-closed variables in these functions is coded in the CallInfo's 37*088332b5SXin Li ** field 'nresults', in a way that functions with no to-be-closed variables 38*088332b5SXin Li ** with zero, one, or "all" wanted results have no overhead. Functions 39*088332b5SXin Li ** with other number of wanted results, as well as functions with 40*088332b5SXin Li ** variables to be closed, have an extra check. 41*088332b5SXin Li */ 42*088332b5SXin Li 43*088332b5SXin Li #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 44*088332b5SXin Li 45*088332b5SXin Li #define codeNresults(n) (-(n) - 3) 46*088332b5SXin Li 47*088332b5SXin Li #endif 48