[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5 and tags
- From: Jamie Webb <j@...>
- Date: Sun, 25 Jul 2004 10:54:38 +0100
On Sun, Jul 25, 2004 at 01:02:16AM +0200, Vincent Penne wrote:
> Alex Sandro Queiroz e Silva wrote:
>
> >Hallo,
> >
> > You can say two objects (userdata or tables) are of the same type
> >if they share the same metatable. If want to refer to your types by
> >name, you can create entries in the global namespace using the type
> >name as a key and the metatable as a value. I guess luaL_newmetatable
> >and luaL_getmetatable do just that.
>
> Ok, I see the idea. I was not aware of these luaL functions, this is
> what I'm going to need. There is even a luaL_checkudata which does
> exactly what I want, that is checking the type of my userdata.
Unfortunately, neither the reference nor PIL covers them. I think
there are some brief descriptions on the lua-users.org Wiki though.
> > You can't associate metatables with light userdata, but they are
> >useful in other contexts. The I/O standard library stores FILE*
> >pointers in light user data.
Actually, the FILE pointers are stored in pointer-sized full userdata.
Hence you can do file:read(), etc.
> Ok ... I can certainly see some use for them, but I suppose you have to
> be careful.
Light userdatas are intended for internal use by a module, where a
full userdata would be overkill. They shouldn't be exposed to user
code, for exactly the reason that you can't typecheck them.
-- Jamie Webb