sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
lapi.h
Go to the documentation of this file.
1/*
2** $Id: lapi.h $
3** Auxiliary functions from Lua API
4** See Copyright Notice in lua.h
5*/
6
11#ifndef lapi_h
12#define lapi_h
13
14
15#include "llimits.h"
16#include "lstate.h"
17
18
19/* Increments 'L->top.p', checking for stack overflows */
20#define api_incr_top(L) {L->top.p++; \
21 api_check(L, L->top.p <= L->ci->top.p, \
22 "stack overflow");}
23
24
25/*
26** If a call returns too many multiple returns, the callee may not have
27** stack space to accommodate all results. In this case, this macro
28** increases its stack space ('L->ci->top.p').
29*/
30#define adjustresults(L,nres) \
31 { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
32 L->ci->top.p = L->top.p; }
33
34
35/* Ensure the stack has at least 'n' elements */
36#define api_checknelems(L,n) \
37 api_check(L, (n) < (L->top.p - L->ci->func.p), \
38 "not enough elements in the stack")
39
40
41/*
42** To reduce the overhead of returning from C functions, the presence of
43** to-be-closed variables in these functions is coded in the CallInfo's
44** field 'nresults', in a way that functions with no to-be-closed variables
45** with zero, one, or "all" wanted results have no overhead. Functions
46** with other number of wanted results, as well as functions with
47** variables to be closed, have an extra check.
48*/
49
50#define hastocloseCfunc(n) ((n) < LUA_MULTRET)
51
52/* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
53#define codeNresults(n) (-(n) - 3)
54#define decodeNresults(n) (-(n) - 3)
55
56#endif