lua-users home
lua-l archive

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


> I missed lua_xmove, lua_dump, lua_topointer and lua_tothread.

We will correct that.


> There also a few macros that would be worth mentioning like lua_boxpointer.

Actually, lua_boxpointer (and lua_unboxpointer) are kind of deprecated
(even before a "true" existence ;-). They are very useful as a
technique, but not as an abstraction (which would be the role of the
macros). Among some of their problems we have:

*) It is unsafe to call `lua_unboxpointer' without first checking
whether we have a userdata of the correct type. The userdata may
not have enough bytes to be read, or worse, the object may not be a
userdata (and the access will generate a seg-fault). The best way to
do the second check is to call `lua_touserdata' and check whether the
result is NULL. Using this macro implies in another (redundant) call to
`lua_touserdata'.

*) Sometimes it is useful to change the pointer inside a "box". We would
need another macro for that.

*) The call `lua_newuserdata' may trigger an `exception' (longjmp), if
there is not enough memory. This may leak the memory you are trying to
store there. It is better to first create the userdata, and only then
create the object to be stored there. (See `newfile' in `liolib.c' for
an example.) `lua_boxpointer' does not promote this practice.

-- Roberto