mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-30 21:20:54 +00:00
Throw an error if too many metatables are registered
This commit is contained in:
parent
1155d875d5
commit
e52cb7f6fa
1 changed files with 4 additions and 1 deletions
|
@ -250,12 +250,15 @@ static int lib_userdataType(lua_State *L)
|
||||||
// Only callable during script loading
|
// Only callable during script loading
|
||||||
static int lib_registerMetatable(lua_State *L)
|
static int lib_registerMetatable(lua_State *L)
|
||||||
{
|
{
|
||||||
static UINT32 nextid = 1;
|
static UINT16 nextid = 1;
|
||||||
|
|
||||||
if (!lua_lumploading)
|
if (!lua_lumploading)
|
||||||
return luaL_error(L, "This function cannot be called from within a hook or coroutine!");
|
return luaL_error(L, "This function cannot be called from within a hook or coroutine!");
|
||||||
luaL_checktype(L, 1, LUA_TTABLE);
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
|
||||||
|
if (nextid == 0)
|
||||||
|
luaL_error(L, "Too many metatables registered?! Please consider rewriting your script once you are sober again.\n");
|
||||||
|
|
||||||
lua_getfield(L, LUA_REGISTRYINDEX, LREG_METATABLES); // 2
|
lua_getfield(L, LUA_REGISTRYINDEX, LREG_METATABLES); // 2
|
||||||
// registry.metatables[metatable] = nextid
|
// registry.metatables[metatable] = nextid
|
||||||
lua_pushvalue(L, 1); // 3
|
lua_pushvalue(L, 1); // 3
|
||||||
|
|
Loading…
Reference in a new issue