Add configurable extra data at the end of lua_State

This commit is contained in:
Petri Häkkinen 2021-11-23 14:18:37 +02:00
parent 6958716ccd
commit ed6491a087
3 changed files with 11 additions and 0 deletions

View file

@ -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

View file

@ -10,6 +10,8 @@
#include "ldo.h"
#include "ldebug.h"
#include <string.h>
/*
** 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));
}

View file

@ -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