1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-05 18:41:05 +00:00

Implement helpful __tostring for all userdata-based classes

This commit is contained in:
Lars Mueller 2025-04-27 17:27:55 +02:00 committed by Lars Müller
parent 9ad23e4384
commit 747857bffa
22 changed files with 103 additions and 66 deletions

View file

@ -90,29 +90,6 @@ 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;