summaryrefslogtreecommitdiff
path: root/external/mit/lua/dist/src/lapi.h
diff options
context:
space:
mode:
authornikita <nikita@NetBSD.org>2023-04-16 20:46:16 +0000
committernikita <nikita@NetBSD.org>2023-04-16 20:46:16 +0000
commit5d7f68298a269c6bcf3c1983f0b9b44e52c5c2bf (patch)
tree3da439acfeacea2d18f0ea1f8ebe5635d1a28fab /external/mit/lua/dist/src/lapi.h
parent3381fb4f9d31004c79eeada1ad64b7e367e1c452 (diff)
Resolve conflicts for lua 5.4.4 import.
Adjust various files for lua 5.4.4.
Diffstat (limited to 'external/mit/lua/dist/src/lapi.h')
-rw-r--r--external/mit/lua/dist/src/lapi.h31
1 files changed, 28 insertions, 3 deletions
diff --git a/external/mit/lua/dist/src/lapi.h b/external/mit/lua/dist/src/lapi.h
index 4e9f83b09e0..07de63cccb5 100644
--- a/external/mit/lua/dist/src/lapi.h
+++ b/external/mit/lua/dist/src/lapi.h
@@ -1,7 +1,7 @@
-/* $NetBSD: lapi.h,v 1.9 2018/08/04 17:30:01 alnsn Exp $ */
+/* $NetBSD: lapi.h,v 1.10 2023/04/16 20:46:17 nikita Exp $ */
/*
-** Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp
+** Id: lapi.h
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
*/
@@ -13,14 +13,39 @@
#include "llimits.h"
#include "lstate.h"
+
+/* Increments 'L->top', checking for stack overflows */
#define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
"stack overflow");}
+
+/*
+** If a call returns too many multiple returns, the callee may not have
+** stack space to accommodate all results. In this case, this macro
+** increases its stack space ('L->ci->top').
+*/
#define adjustresults(L,nres) \
- { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
+ { 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")
+/*
+** 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)
+
+/* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
+#define codeNresults(n) (-(n) - 3)
+#define decodeNresults(n) (-(n) - 3)
+
#endif