|
Matthew Metnetsky wrote:
lua_tostring can throw off lua_next. You can use lua_pushvalue to create a copy of the item and then use lua_tostring on that copy (then pop the copy) and lua_next will still be good-to-go.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?