/*1** $Id: lapi.h $2** Auxiliary functions from Lua API3** See Copyright Notice in lua.h4*/56#ifndef lapi_h7#define lapi_h8910#include "llimits.h"11#include "lstate.h"121314/* Increments 'L->top.p', checking for stack overflows */15#define api_incr_top(L) {L->top.p++; \16api_check(L, L->top.p <= L->ci->top.p, \17"stack overflow");}181920/*21** If a call returns too many multiple returns, the callee may not have22** stack space to accommodate all results. In this case, this macro23** increases its stack space ('L->ci->top.p').24*/25#define adjustresults(L,nres) \26{ if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \27L->ci->top.p = L->top.p; }282930/* Ensure the stack has at least 'n' elements */31#define api_checknelems(L,n) \32api_check(L, (n) < (L->top.p - L->ci->func.p), \33"not enough elements in the stack")343536/*37** To reduce the overhead of returning from C functions, the presence of38** to-be-closed variables in these functions is coded in the CallInfo's39** field 'nresults', in a way that functions with no to-be-closed variables40** with zero, one, or "all" wanted results have no overhead. Functions41** with other number of wanted results, as well as functions with42** variables to be closed, have an extra check.43*/4445#define hastocloseCfunc(n) ((n) < LUA_MULTRET)4647/* Map [-1, inf) (range of 'nresults') into (-inf, -2] */48#define codeNresults(n) (-(n) - 3)49#define decodeNresults(n) (-(n) - 3)5051#endif525354