Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:37:53

0001 /*
0002 ** $Id: lapi.h $
0003 ** Auxiliary functions from Lua API
0004 ** See Copyright Notice in lua.h
0005 */
0006 
0007 #ifndef lapi_h
0008 #define lapi_h
0009 
0010 
0011 #include "llimits.h"
0012 #include "lstate.h"
0013 
0014 
0015 /* Increments 'L->top.p', checking for stack overflows */
0016 #define api_incr_top(L) {L->top.p++; \
0017              api_check(L, L->top.p <= L->ci->top.p, \
0018                     "stack overflow");}
0019 
0020 
0021 /*
0022 ** If a call returns too many multiple returns, the callee may not have
0023 ** stack space to accommodate all results. In this case, this macro
0024 ** increases its stack space ('L->ci->top.p').
0025 */
0026 #define adjustresults(L,nres) \
0027     { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
0028     L->ci->top.p = L->top.p; }
0029 
0030 
0031 /* Ensure the stack has at least 'n' elements */
0032 #define api_checknelems(L,n) \
0033     api_check(L, (n) < (L->top.p - L->ci->func.p), \
0034               "not enough elements in the stack")
0035 
0036 
0037 /*
0038 ** To reduce the overhead of returning from C functions, the presence of
0039 ** to-be-closed variables in these functions is coded in the CallInfo's
0040 ** field 'nresults', in a way that functions with no to-be-closed variables
0041 ** with zero, one, or "all" wanted results have no overhead. Functions
0042 ** with other number of wanted results, as well as functions with
0043 ** variables to be closed, have an extra check.
0044 */
0045 
0046 #define hastocloseCfunc(n)  ((n) < LUA_MULTRET)
0047 
0048 /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
0049 #define codeNresults(n)     (-(n) - 3)
0050 #define decodeNresults(n)   (-(n) - 3)
0051 
0052 #endif