lua-users home
lua-l archive

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


On Tue, Jul 06, 2004 at 09:53:28AM -0700, Peter Bradshaw wrote:
> (I've only been a lua user for about a month, so I may be about to get
> rudely slapped for inaccuracy).
> 
> Light userdata sounds like exactly what you want. You just push a
> pointer into lua and that's what you get back.
> 
> Setting the metatable from C and then checking it seems to be the way
> to ensure type safety.

Unfortunately, this won't work, because light userdatas cannot have
metatables. They are intended for internal use by C modules, and
shouldn't generally be shown to Lua code.

The principal is about right though. You want a full userdata that
contains just a pointer. Then you can use a metatable for type
checking and to provide the object with methods.

-- Jamie Webb