[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Getting metatable's name.
- From: Sean Conner <sean@...>
- Date: Sat, 27 Feb 2021 18:48:08 -0500
It was thus said that the Great Laurent FAILLIE once stated:
>
> So, now, from Lua's side, how to retrieve metatable's name ???? (in my case, "SelTimedWindowCollection")
> I tried to test against the metatable itself but it doesn't work :
> print( getmetatable(col.getCollection()), SelTimedWindowCollection )-> table: 0xb79650d8 table: 0xb7965100
Starting with Lua 5.3, the metatable will have a __name field, as
mentioned in the documentation for luaL_newmetatable(). For earlier
versions of Lua, you will have to call debug.getregistry() and manually scan
it for the name.
mt = getmetatable(thing)
reg = debug.getregistry()
for name,value in pairs(reg) do
if value == mt then
print(name)
break
end
end
-spc