1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Store vector metatable in registry

This commit is contained in:
Jude Melton-Houghton 2022-03-29 12:07:00 -04:00 committed by GitHub
parent 11aab4198b
commit 06d197cdd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 21 deletions

View file

@ -121,6 +121,14 @@ ScriptApiBase::ScriptApiBase(ScriptingType type):
lua_newtable(m_luastack);
lua_setglobal(m_luastack, "core");
// vector.metatable is stored in the registry for quick access from C++.
lua_newtable(m_luastack);
lua_rawseti(m_luastack, LUA_REGISTRYINDEX, CUSTOM_RIDX_VECTOR_METATABLE);
lua_newtable(m_luastack);
lua_rawgeti(m_luastack, LUA_REGISTRYINDEX, CUSTOM_RIDX_VECTOR_METATABLE);
lua_setfield(m_luastack, -2, "metatable");
lua_setglobal(m_luastack, "vector");
if (m_type == ScriptingType::Client)
lua_pushstring(m_luastack, "/");
else

View file

@ -98,6 +98,7 @@ void ScriptApiSecurity::initializeSecurity()
"type",
"unpack",
"_VERSION",
"vector",
"xpcall",
};
static const char *whitelist_tables[] = {
@ -254,6 +255,10 @@ void ScriptApiSecurity::initializeSecurity()
lua_pushnil(L);
lua_setfield(L, old_globals, "core");
// 'vector' as well.
lua_pushnil(L);
lua_setfield(L, old_globals, "vector");
lua_pop(L, 1); // Pop globals_backup
@ -296,6 +301,7 @@ void ScriptApiSecurity::initializeSecurityClient()
"type",
"unpack",
"_VERSION",
"vector",
"xpcall",
// Completely safe libraries
"coroutine",