1997-09-16 23:25:59 +04:00
|
|
|
/*
|
2018-08-23 20:26:12 +03: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
|
|
|
|
|
|
|
|
|
2006-07-11 19:53:29 +04:00
|
|
|
#include "llimits.h"
|
|
|
|
#include "lstate.h"
|
1997-09-16 23:25:59 +04:00
|
|
|
|
2019-07-25 19:55:29 +03:00
|
|
|
|
2024-06-20 19:43:33 +03:00
|
|
|
#if defined(LUA_USE_APICHECK)
|
|
|
|
#include <assert.h>
|
|
|
|
#define api_check(l,e,msg) assert(e)
|
|
|
|
#else /* for testing */
|
|
|
|
#define api_check(l,e,msg) ((void)(l), lua_assert((e) && msg))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-29 18:06:37 +03:00
|
|
|
/* Increments 'L->top.p', checking for stack overflows */
|
2024-01-29 20:29:24 +03:00
|
|
|
#define api_incr_top(L) \
|
|
|
|
(L->top.p++, api_check(L, L->top.p <= L->ci->top.p, "stack overflow"))
|
1997-09-16 23:25:59 +04:00
|
|
|
|
2019-07-25 19:55:29 +03:00
|
|
|
|
2024-06-20 19:43:33 +03:00
|
|
|
/*
|
|
|
|
** macros that are executed whenever program enters the Lua core
|
|
|
|
** ('lua_lock') and leaves the core ('lua_unlock')
|
|
|
|
*/
|
|
|
|
#if !defined(lua_lock)
|
|
|
|
#define lua_lock(L) ((void) 0)
|
|
|
|
#define lua_unlock(L) ((void) 0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-25 19:55:29 +03: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
|
2022-10-29 18:06:37 +03:00
|
|
|
** increases its stack space ('L->ci->top.p').
|
2019-07-25 19:55:29 +03:00
|
|
|
*/
|
2009-03-10 20:14:37 +03:00
|
|
|
#define adjustresults(L,nres) \
|
2022-10-29 18:06:37 +03:00
|
|
|
{ if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
|
|
|
|
L->ci->top.p = L->top.p; }
|
2009-03-10 20:14:37 +03:00
|
|
|
|
2019-07-25 19:55:29 +03:00
|
|
|
|
|
|
|
/* Ensure the stack has at least 'n' elements */
|
2022-10-29 18:06:37 +03:00
|
|
|
#define api_checknelems(L,n) \
|
2024-03-11 20:05:06 +03:00
|
|
|
api_check(L, (n) < (L->top.p - L->ci->func.p), \
|
|
|
|
"not enough elements in the stack")
|
|
|
|
|
|
|
|
|
|
|
|
/* Ensure the stack has at least 'n' elements to be popped. (Some
|
|
|
|
** functions only update a slot after checking it for popping, but that
|
|
|
|
** is only an optimization for a pop followed by a push.)
|
|
|
|
*/
|
|
|
|
#define api_checkpop(L,n) \
|
|
|
|
api_check(L, (n) < L->top.p - L->ci->func.p && \
|
|
|
|
L->tbclist.p < L->top.p - (n), \
|
|
|
|
"not enough free elements in the stack")
|
2009-11-27 18:37:59 +03:00
|
|
|
|
2009-03-10 20:14:37 +03:00
|
|
|
|
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)
|
|
|
|
|
2021-02-12 19:36:30 +03:00
|
|
|
/* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
|
2018-10-25 21:30:15 +03:00
|
|
|
#define codeNresults(n) (-(n) - 3)
|
2021-02-12 19:36:30 +03:00
|
|
|
#define decodeNresults(n) (-(n) - 3)
|
2018-10-25 21:30:15 +03:00
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
#endif
|