[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: gc tag
- From: "Leiradella, Andre V Matos Da Cunha" <ANDRE.LEIRADELLA@...>
- Date: Wed, 31 Oct 2001 13:38:40 -0200
Hi All,
>From the reference manual, section 4.8 Tag Methods, I can see that the Lua
function that describes the behavior of the "gc" event does not return any
value.
I'm writing C functions to free memory used by my userdata types. All they
do is something like:
-----cut-----
static int gcImage(lua_State *L) {
image_t *image;
image=luaL_check_tag(L,1,imageTag);
free_image(image);
return 0;
}
-----cut-----
where luaL_check_tag is a function I created inside lauxlib.c to print an
user-friendly error message in case there is a tag mismatch:
-----cut-----
LUALIB_API void *luaL_check_tag(lua_State *L,int narg,int tag) {
if (lua_tag(L,narg)!=tag)
tag_error(L,narg,tag);
return lua_touserdata(L,narg);
}
-----cut-----
Am I supposed to return something from the C gc tag method? The reason I'm
asking this is because I'm getting random segfaults inside lua
(ltable.c:luaH_getstr and/or lstring.c:luaS_newlstr) and everything in my
code seems to be ok except for this doubt regarding gc tag methods. I'm
using Lua 4.1 alpha and everything is compiled with MingW.
Another question: is it safe to call lua_unref from a thread other than the
one that is executing my lua code? I'm using an audio library that runs in
its own thread and has a callback mechanism to flag when a music or chunk of
sound has finished playing. I call lua_ref when the music/sound starts and I
want to call lua_unref inside the callback function. If I can't do that, is
it safe to put a semaphore around lua_unref (or some other function - which
one?) to make it safe?
Regards,
Andre de Leiradella