Пример #1
0
static void push_move_map(lua_State *L, const move_map& m)
{
	move_map::const_iterator it = m.begin();

	int index = 1;

	lua_createtable(L, 0, 0); // the main table

	do {
		map_location key = it->first;

		push_map_location(L, key);
		lua_createtable(L, 0, 0);

		while (key == it->first) {

			push_map_location(L, it->second);
			lua_rawseti(L, -2, index);

			++index;
			++it;

		}

		lua_settable(L, -3);

		index = 1;

	} while (it != m.end());
}
Пример #2
0
static void push_move_map(lua_State *L, const move_map& m)
{
	lua_createtable(L, 0, 0); // the main table

	if (m.empty())
	{
		return;
	}

	move_map::const_iterator it = m.begin();

	int index = 1;



	do
	{
		map_location key = it->first;

		//push_map_location(L, key); // deprecated

		// This should be factored out. The same function is defined in data/lua/location_set.lua
		// At this point, it is not clear, where this(hashing) function can be placed
		// Implemented it this way, to test the new version of the data structure
		// as requested from the users of LuaAI <Nephro>
		int hashed_index = (key.x + 1) * 16384 + (key.y + 1) + 2000;
		lua_pushinteger(L, hashed_index);

		lua_createtable(L, 0, 0);

		while (key == it->first) {

			push_map_location(L, it->second);
			lua_rawseti(L, -2, index);

			++index;
			++it;

		}

		lua_settable(L, -3);

		index = 1;

	} while (it != m.end());
}