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

Merge branch 'luanti-org:master' into skybox

This commit is contained in:
Mircea Kitsune 2025-05-31 19:11:45 +03:00 committed by GitHub
commit 79f46800f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
282 changed files with 72639 additions and 24769 deletions

View file

@ -69,8 +69,27 @@ RemotePlayer *ObjectRef::getplayer(ObjectRef *ref)
// Exported functions
int ObjectRef::mt_tostring(lua_State *L)
{
auto *ref = checkObject<ObjectRef>(L, 1);
if (getobject(ref)) {
if (auto *player = getplayer(ref)) {
lua_pushfstring(L, "ObjectRef (player): %s", player->getName().c_str());
} else if (auto *entitysao = getluaobject(ref)) {
lua_pushfstring(L, "ObjectRef (entity): %s (id: %d)",
entitysao->getName().c_str(), entitysao->getId());
} else {
lua_pushfstring(L, "ObjectRef (?): %p", ref);
}
} else {
lua_pushfstring(L, "ObjectRef (invalid): %p", ref);
}
return 1;
}
// garbage collector
int ObjectRef::gc_object(lua_State *L) {
int ObjectRef::gc_object(lua_State *L)
{
ObjectRef *obj = *(ObjectRef **)(lua_touserdata(L, 1));
delete obj;
return 0;
@ -2809,9 +2828,10 @@ void ObjectRef::Register(lua_State *L)
{
static const luaL_Reg metamethods[] = {
{"__gc", gc_object},
{"__tostring", mt_tostring},
{0, 0}
};
registerClass(L, className, methods, metamethods);
registerClass<ObjectRef>(L, methods, metamethods);
}
const char ObjectRef::className[] = "ObjectRef";