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

Consolidate API object code (#12728)

Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
Jude Melton-Houghton 2022-10-04 08:31:36 -04:00 committed by GitHub
parent b21fb18379
commit 7632af3c73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 463 additions and 1079 deletions

View file

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