Пример #1
0
bool lua_details::listTable(lua_State* L, int idx, TableInfo& out, int recursive)
{
	out.clear();

	if (lua_type(L, idx) != LUA_TTABLE)
		return false;

	UInt32 size= getNumFields(L, idx);

	out.reserve(size);

	// table to traverse
	lua_pushvalue(L, idx);

	// push a key
	lua_pushnil(L);

	popStackElements pop(L, 2);	// remove key & table off the stack at the end of this fn
//	popStackElements pop(L, 1);	// remove table off the stack at the end of this fn

	int table= lua_gettop(L) - 1;

	// traverse a table
	while (lua_next(L, table))
	{
		popStackElements pop(L, 1);

        Value Key(L, -2);
        Value Val(L, -1, recursive);
		LuaField field(Key,Val);

		out.push_back(field);
	}

	pop.dec();	// final lua_next call removed key

	return true;
}
Пример #2
0
bool lua_details::list_table(lua_State* L, int idx, TableInfo& out, int recursive)
{
	out.clear();

	if (lua_type(L, idx) != LUA_TTABLE)
		return false;

	int size= lua_objlen(L, idx);

	out.reserve(size);

	// table to traverse
	lua_pushvalue(L, idx);

	// push a key
	lua_pushnil(L);

	pop_stack_elements pop(L, 2);	// remove key & table off the stack at the end of this fn
//	pop_stack_elements pop(L, 1);	// remove table off the stack at the end of this fn

	int table= lua_gettop(L) - 1;

	// traverse a table
	while (lua_next(L, table))
	{
		pop_stack_elements pop(L, 1);

		LuaField field;
		capture_value(L, field.key, -2);
		capture_value(L, field.val, -1, recursive);

		out.push_back(field);
	}

	pop.dec();	// final lua_next call removed key

	return true;
}