[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: The "make the special type in C" journey and type
- From: Sean Conner <sean@...>
- Date: Thu, 3 Oct 2013 19:26:06 -0400
It was thus said that the Great liam mail once stated:
> I agree with Justin here for userdata types, in fact a certain library
> does not even know the types of userdata in C++ which is not so
> unusual. If you really wanted to check the type then using the debug
> library seems very very wrong to me; just don't set a __metatable entry to
> hide it, grab the metatable and check against the type you want.
Be careful, because that isn't always true. I wrote code to bind Xlib to
Lua , and each userdata created gets its own distinct metatable.  Of
course, that metatable has a _TYPE field associated with it ...
>  OOLua
>  It has no __tostring method either as this would reveal an
> implementation details and would surprise some users I am sure.
>  luaL_checkudata which is not used in  does not even know the type,
> it checks to see if it is a certain requested type
 Why Xlib? Why not? I like playing around with implementing user
interfaces from scratch.
 Because I wanted a way to associate extra data with a userdata type,
and by giving each userdata its own metatable, I can stash do the
association. So, for instance:
w = display:window(...)
w.annotate = "This is a top level window"