lua/lapi.h

48 lines
1.3 KiB
C
Raw Normal View History

1997-09-16 23:25:59 +04:00
/*
** $Id: lapi.h $
1998-06-19 20:14:09 +04:00
** Auxiliary functions from Lua API
1997-09-16 23:25:59 +04:00
** See Copyright Notice in lua.h
*/
#ifndef lapi_h
#define lapi_h
#include "llimits.h"
#include "lstate.h"
1997-09-16 23:25:59 +04:00
/* Increments 'L->top', checking for stack overflows */
#define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
"stack overflow");}
1997-09-16 23:25:59 +04:00
/*
** If a call returns too many multiple returns, the callee may not have
2019-12-30 17:45:08 +03:00
** stack space to accommodate all results. In this case, this macro
** increases its stack space ('L->ci->top').
*/
#define adjustresults(L,nres) \
2018-10-25 21:30:15 +03:00
{ if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
/* Ensure the stack has at least 'n' elements */
#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
"not enough elements in the stack")
2018-10-25 21:30:15 +03:00
/*
** To reduce the overhead of returning from C functions, the presence of
** to-be-closed variables in these functions is coded in the CallInfo's
** field 'nresults', in a way that functions with no to-be-closed variables
** with zero, one, or "all" wanted results have no overhead. Functions
** with other number of wanted results, as well as functions with
** variables to be closed, have an extra check.
*/
#define hastocloseCfunc(n) ((n) < LUA_MULTRET)
#define codeNresults(n) (-(n) - 3)
1997-09-16 23:25:59 +04:00
#endif