aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_base.cpp
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-10-04 08:31:36 -0400
committerGitHub <noreply@github.com>2022-10-04 08:31:36 -0400
commit7632af3c73fc4e4ae3ad4c98c90c39b47c3b8379 (patch)
tree08b974d6ecafb6c20de565f96e329748030c1519 /src/script/lua_api/l_base.cpp
parentb21fb1837955e6385137184cac906245821b20e4 (diff)
downloadminetest-7632af3c73fc4e4ae3ad4c98c90c39b47c3b8379.tar.xz
Consolidate API object code (#12728)
Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'src/script/lua_api/l_base.cpp')
-rw-r--r--src/script/lua_api/l_base.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp
index f842671b8..03d8ee62d 100644
--- a/src/script/lua_api/l_base.cpp
+++ b/src/script/lua_api/l_base.cpp
@@ -100,6 +100,29 @@ bool ModApiBase::registerFunction(lua_State *L, const char *name,
return true;
}
+void ModApiBase::registerClass(lua_State *L, const char *name,
+ const luaL_Reg *methods,
+ const luaL_Reg *metamethods)
+{
+ luaL_newmetatable(L, name);
+ luaL_register(L, NULL, metamethods);
+ int metatable = lua_gettop(L);
+
+ lua_newtable(L);
+ luaL_register(L, NULL, methods);
+ int methodtable = lua_gettop(L);
+
+ lua_pushvalue(L, methodtable);
+ lua_setfield(L, metatable, "__index");
+
+ // Protect the real metatable.
+ lua_pushvalue(L, methodtable);
+ lua_setfield(L, metatable, "__metatable");
+
+ // Pop methodtable and metatable.
+ lua_pop(L, 2);
+}
+
int ModApiBase::l_deprecated_function(lua_State *L, const char *good, const char *bad, lua_CFunction func)
{
thread_local std::vector<u64> deprecated_logged;