lua-users home
lua-l archive

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


> In a Lua binding there is the added possibility of allocating the
> required memory via lua_newuserdata.

If you can use lua_newuserdata, then by all means use it. It depends on
what library you're binding to Lua. There are two types of libraries
that use heap objects: those that create (ie allocate) the object
themselves and those that expect the user to do it. For the first type,
you use lua_newuserdata for the pointer only and you need to set up a
gc method to free or close the object. For the second type, you can use
lua_newuserdata for the complete object and there is no need to box the
pointer or for a gc method. lbc and lbn are example of the first type;
lmd5 and lrandom are examples of the second type.

See http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/ .