lua-users home
lua-l archive

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


Can someone explain what is wrong with this code?
I am using lua 3.2 and after a number of calls (300
or so) to these functions, my app simply exits.
There doesn't appear to be any lua error, but
removing this code (and simply hardcoding the
return values) fixes the problem.

I am thinking it is something related to the 
lua stack.

int Properties_GetNumItems( lua_Object Table )
{
	int i = 0;
	int c = 0;

	lua_beginblock();
	while ((i = lua_next(Table, i)) != 0) {
		c++;
	}
	lua_endblock();


	return c;
}

//

const char *Properties_GetItemKey( lua_Object Table, int ItemNum )
{
	int i = 0;
	int c = 0;
	const char *ret = NULL;

	lua_beginblock();

	while ((i = lua_next(Table, i)) != 0) {
		lua_Object o = lua_getresult(1);
		if( c == ItemNum ) {
			ret = lua_getstring( o );
			break;
		}
		c++;
	}

	lua_endblock();

	return ret;
}

Thanks,
Paul