lua-users home
lua-l archive

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


> 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