|
| 1 | +/* |
| 2 | +** $Id: lapi.h $ |
| 3 | +** Auxiliary functions from Lua API |
| 4 | +** See Copyright Notice in lua.h |
| 5 | +*/ |
| 6 | + |
| 7 | +#ifndef lapi_h |
| 8 | +#define lapi_h |
| 9 | + |
| 10 | + |
| 11 | +#include "llimits.h" |
| 12 | +#include "lstate.h" |
| 13 | + |
| 14 | + |
| 15 | +#if defined(LUA_USE_APICHECK) |
| 16 | +#include <assert.h> |
| 17 | +#define api_check(l,e,msg) assert(e) |
| 18 | +#else /* for testing */ |
| 19 | +#define api_check(l,e,msg) ((void)(l), lua_assert((e) && msg)) |
| 20 | +#endif |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +/* Increments 'L->top.p', checking for stack overflows */ |
| 25 | +#define api_incr_top(L) \ |
| 26 | + (L->top.p++, api_check(L, L->top.p <= L->ci->top.p, "stack overflow")) |
| 27 | + |
| 28 | + |
| 29 | +/* |
| 30 | +** macros that are executed whenever program enters the Lua core |
| 31 | +** ('lua_lock') and leaves the core ('lua_unlock') |
| 32 | +*/ |
| 33 | +#if !defined(lua_lock) |
| 34 | +#define lua_lock(L) ((void) 0) |
| 35 | +#define lua_unlock(L) ((void) 0) |
| 36 | +#endif |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +/* |
| 41 | +** If a call returns too many multiple returns, the callee may not have |
| 42 | +** stack space to accommodate all results. In this case, this macro |
| 43 | +** increases its stack space ('L->ci->top.p'). |
| 44 | +*/ |
| 45 | +#define adjustresults(L,nres) \ |
| 46 | + { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \ |
| 47 | + L->ci->top.p = L->top.p; } |
| 48 | + |
| 49 | + |
| 50 | +/* Ensure the stack has at least 'n' elements */ |
| 51 | +#define api_checknelems(L,n) \ |
| 52 | + api_check(L, (n) < (L->top.p - L->ci->func.p), \ |
| 53 | + "not enough elements in the stack") |
| 54 | + |
| 55 | + |
| 56 | +/* Ensure the stack has at least 'n' elements to be popped. (Some |
| 57 | +** functions only update a slot after checking it for popping, but that |
| 58 | +** is only an optimization for a pop followed by a push.) |
| 59 | +*/ |
| 60 | +#define api_checkpop(L,n) \ |
| 61 | + api_check(L, (n) < L->top.p - L->ci->func.p && \ |
| 62 | + L->tbclist.p < L->top.p - (n), \ |
| 63 | + "not enough free elements in the stack") |
| 64 | + |
| 65 | +#endif |
0 commit comments