From ed6491a087b407885a383ee1111ee46a6b001dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petri=20H=C3=A4kkinen?= Date: Tue, 23 Nov 2021 14:18:37 +0200 Subject: [PATCH] Add configurable extra data at the end of lua_State --- VM/include/luaconf.h | 3 +++ VM/src/lstate.cpp | 5 +++++ VM/src/lstate.h | 3 +++ 3 files changed, 11 insertions(+) diff --git a/VM/include/luaconf.h b/VM/include/luaconf.h index cce70a20..03b9e959 100644 --- a/VM/include/luaconf.h +++ b/VM/include/luaconf.h @@ -126,3 +126,6 @@ #define LUA_VECTOR_SIZE 3 /* must be 3 or 4 */ #define LUA_EXTRA_SIZE LUA_VECTOR_SIZE - 2 + +/* size of optional extra data in bytes added at the end of lua_State. */ +#define LUA_STATE_EXTRA 0 diff --git a/VM/src/lstate.cpp b/VM/src/lstate.cpp index 24e97063..d7316132 100644 --- a/VM/src/lstate.cpp +++ b/VM/src/lstate.cpp @@ -10,6 +10,8 @@ #include "ldo.h" #include "ldebug.h" +#include + /* ** Main thread combines a thread state and the global state */ @@ -78,6 +80,9 @@ static void preinit_state(lua_State* L, global_State* g) L->stackstate = 0; L->activememcat = 0; L->userdata = NULL; +#if LUA_STATE_EXTRA > 0 + memset(L->extra, 0, LUA_STATE_EXTRA); +#endif setnilvalue(gt(L)); } diff --git a/VM/src/lstate.h b/VM/src/lstate.h index 56379883..837e1740 100644 --- a/VM/src/lstate.h +++ b/VM/src/lstate.h @@ -237,6 +237,9 @@ struct lua_State TString* namecall; /* when invoked from Luau using NAMECALL, what method do we need to invoke? */ void* userdata; +#if LUA_STATE_EXTRA > 0 + char extra[LUA_STATE_EXTRA]; +#endif }; // clang-format on