lua-users home
lua-l archive

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


Hi all,

I wrote a small library to add some functionality I was missing to 
Lua. It basically exposes some dangerous Lua API functions to the 
language, but I thought someone else could find a use for it: 
http://www.geocities.com/andre_leiradella/lreflib.tar.gz

>From the README file:

This library exposes the lua API functions lua_ref, lua_getref, 
lua_unref, lua_settag (for user data) and lua_settagmethod (for "gc" 
events) to lua programs. IT IS POTENTIALY DANGEROUS to let end users 
build programs using those functions:

. Referenced objects are not garbage-collected unless they are 
explicitly unreferenced with unref();
. Changing the tag of userdata can make your program crash (i.e. 
calling a socket function with a regex userdata);
. Assigning the reference being garbage collected to another variable 
can make your program crash (I think it's safe to do it with the 
referenced object);
. References are not tagged so any userdata can be passed to getref 
and unref.

The lua functions provided by this library are:

. newref(obj): returns a reference to obj via a call to lua_ref;
. getref(ref): returns the referenced object or nil on error;
. unref(ref): clears the reference;
. setudtag(ud,tag): sets the tag for the given userdata;
. setgctagmethod(tag,func): sets the gc tag method for the tag and 
returns the old tag method.

Please send questions/comments/bugs. Have fun!

Regards,

Andre de Leiradella