summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lua/src/lapi.h
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lua/src/lapi.h')
-rw-r--r--3rdparty/lua/src/lapi.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/3rdparty/lua/src/lapi.h b/3rdparty/lua/src/lapi.h
index 6d36dee3fb7..9e99cc44824 100644
--- a/3rdparty/lua/src/lapi.h
+++ b/3rdparty/lua/src/lapi.h
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $
+** $Id: lapi.h $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
*/
@@ -11,14 +11,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