[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Type of userdata
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 12 Jan 2012 22:25:49 +0200
2012/1/12 Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>> Is there any way to find out from Lua what the registry type of a
>> userdata is, short
>> of giving it a `type` method?
>
> If you used luaL_newmetatable to assign a metatable to the udata,
> then you can search the registry for an entry whose value is that
> metatable. The key is then the "type" you seek.
>
> This example print "FILE*":
>
> t=getmetatable(io.stdin)
> for k,v in pairs(debug.getregistry()) do
> if v==t then print(k) end
> end
>
>
Aha! Thanks!