lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Thanks for your reply.
Any issue if in the metatable creation code, I'm adding manually a field __name when under < 5.3 ?

So the remaining of the code will be the same  whatever Lua's version :)


Le dimanche 28 février 2021 à 00:48:51 UTC+1, Sean Conner <sean@conman.org> a écrit :


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