lua-users home
lua-l archive

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


On Wed, Oct 15, 2008 at 06:00:24PM -0400, Matthew Metnetsky wrote:
> All,
> 
> Based on another question and a members suggestion I'm trying to use luaL_ref
> to get a reference to a LUA_TFUNCTION for usage later. My config (in Lua) looks like
> so:
> 
> 	application = {
> 		exec = '/bin/ls',
> 		can_restart = function(exit_code)
> 			return exit_code ~= 0
> 		end
> 	} 
> 
> 
> After loading the config I find the application table and loop over it's
> values like so:
> 
> 	while (lua_next(priv->L, -2) != 0) { // key = -2 || value -1
> 		GValue gvalue;
> 		memset(&gvalue, 0, sizeof(GValue));
> 
> 		if (LUA_TSTRING == lua_type(priv->L, -1)) {
> 			g_value_init(&gvalue, G_TYPE_STRING);
> 			g_value_set_static_string(&gvalue, lua_tostring(priv->L, -1));
> 		} else if (LUA_TNUMBER == lua_type(priv->L, -1)) {
> 			g_value_init(&gvalue, G_TYPE_INT);
> 			g_value_set_int(&gvalue, (gint)lua_tointeger(priv->L, -1));
> 		} else if (LUA_TFUNCTION == lua_type(priv->L, -1)) {
> 			g_value_init(&gvalue, G_TYPE_INT);
> 			g_value_set_int(&gvalue, luaL_ref(priv->L, -1));

I realized my first email wasn't quite clear. 

When calling luaL_ref like shown above within valgrind I start getting tons of
'Invalid read' messages. If I set the second argument of -1 to 1 I get a ref
of 1, but then calling lua_next I get a fun error:

	PANIC: unprotected error in call to Lua API (invalid key to 'next')

Thoughts?

~ Matthew

Attachment: signature.asc
Description: Digital signature