Beispiel #1
0
void push_groups(lua_State *L, const ItemGroupList &groups)
{
	lua_newtable(L);
	for (ItemGroupList::const_iterator it = groups.begin(); it != groups.end(); ++it) {
		lua_pushnumber(L, it->second);
		lua_setfield(L, -2, it->first.c_str());
	}
}
Beispiel #2
0
std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups)
{
	std::ostringstream os(std::ios::binary);
	writeU8(os, GENERIC_CMD_UPDATE_ARMOR_GROUPS);
	writeU16(os, armor_groups.size());
	for(ItemGroupList::const_iterator i = armor_groups.begin();
			i != armor_groups.end(); i++){
		os<<serializeString(i->first);
		writeS16(os, i->second);
	}
	return os.str();
}
Beispiel #3
0
std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups)
{
	std::ostringstream os(std::ios::binary);
	writeU8(os, GENERIC_CMD_UPDATE_ARMOR_GROUPS);
	writeU16(os, armor_groups.size());
	for (const auto &armor_group : armor_groups) {
		os<<serializeString(armor_group.first);
		writeS16(os, armor_group.second);
	}
	return os.str();
}
Beispiel #4
0
void read_groups(lua_State *L, int index, ItemGroupList &result)
{
	if (!lua_istable(L,index))
		return;
	result.clear();
	lua_pushnil(L);
	if(index < 0)
		index -= 1;
	while(lua_next(L, index) != 0){
		// key at index -2 and value at index -1
		std::string name = luaL_checkstring(L, -2);
		int rating = luaL_checkinteger(L, -1);
		result[name] = rating;
		// removes value, keeps key for next iteration
		lua_pop(L, 1);
	}
}