lua-users home
lua-l archive

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


>lua_getglobal( L,"enum" );
>lua_pushnil(L);
>while( lua_next(L,1) ) {
>    key = lua_tostring(L,-2);
>    val = lua_tostring(L,-1);
>    lua_pop(L,1);
>}
>
>First itertion gives me good results (ie. key/val = 1/one), but second
>iteration is terminated in lua_next (application falls down).

key = lua_tostring(L,-2) converts the object at -2 to a string; it used
to be a number, and this messes up the information that lua_next needs.

This is unfortunate. We'll try to improe this in 4.1.

You have to do something like this:
	val = lua_tostring(L,-1);
	lua_pushvalue(L,-2);
	key = lua_tostring(L,-1);
	lua_pop(L,2);

--lhf