lua-users home
lua-l archive

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


On Fri, Feb 02, 2007 at 02:36:57PM -0500, Rici Lake wrote:
> On 2-Feb-07, at 2:15 PM, Zé Pedro wrote:
> 
> >I don't think I made myself clear. What happens is that the function 
> >in C++ that is called from lua can receive different types of 
> >userdata. When I do luaL_checkudata I have to say what kind of 
> >userdata I'm going to read. What I want to do is to check what kind of 
> >userdata was sent from Lua.
> 
> Yes, I understood that. My suggestion is that you put something in the 
> metatable when you create it, so that you can later get that 
> information back out of the metatable of the argument to the cfunction.

Rici knows this stuff inside out, you should probably do as he says. :-)

But if you don't have control over the creation of the metadata, you can
search the registry table for an entry who's value is the userdata's
metadata, the key should be the "tname" of the userdata. Maybe not
efficient, though.

It looks like in lua 5.0.2, luaL_newmetatable put two entries in the
registry, one to map the tname to the metadata, and the other to map the
metadata to the tname. So this would be easier if you aren't using 5.1.

Cheers,
Sam