From e9d4ee7a33c1d586a2d037244166a0e9fedc1dbe Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Tue, 6 Dec 2022 19:20:24 +0000 Subject: [PATCH] Make pseudo-indices relative to LUAI_MAXCSTACK (#766) This is useful in particular if redefine `LUAI_MAXCSTACK` to a higher value than the current one (8000). Ie. passing `-D LUAI_MAXCSTACK=1000000` would not work as overlaps with `LUA_REGISTRYINDEX` and below. --- VM/include/lua.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VM/include/lua.h b/VM/include/lua.h index 73ebbb0..783e60a 100644 --- a/VM/include/lua.h +++ b/VM/include/lua.h @@ -17,9 +17,9 @@ /* ** pseudo-indices */ -#define LUA_REGISTRYINDEX (-10000) -#define LUA_ENVIRONINDEX (-10001) -#define LUA_GLOBALSINDEX (-10002) +#define LUA_REGISTRYINDEX (-LUAI_MAXCSTACK - 2000) +#define LUA_ENVIRONINDEX (-LUAI_MAXCSTACK - 2001) +#define LUA_GLOBALSINDEX (-LUAI_MAXCSTACK - 2002) #define lua_upvalueindex(i) (LUA_GLOBALSINDEX - (i)) #define lua_ispseudo(i) ((i) <= LUA_REGISTRYINDEX)