aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_base.cpp
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-03-29 12:07:00 -0400
committerGitHub <noreply@github.com>2022-03-29 18:07:00 +0200
commit06d197cdd042392e1551e5e7244c61300a6bb4e3 (patch)
treec47a0c58917f5f89af1c5128e42611d0d8a3d320 /src/script/cpp_api/s_base.cpp
parent11aab4198be1a0f1104a433896e908e4c86de0c9 (diff)
downloadminetest-06d197cdd042392e1551e5e7244c61300a6bb4e3.tar.xz
Store vector metatable in registry
Diffstat (limited to 'src/script/cpp_api/s_base.cpp')
-rw-r--r--src/script/cpp_api/s_base.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp
index f7b8a5102..595c9e540 100644
--- a/src/script/cpp_api/s_base.cpp
+++ b/src/script/cpp_api/s_base.cpp
@@ -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