Add matches method to team metatable

This commit is contained in:
Celtic Minstrel 2016-09-11 14:28:57 -04:00
parent b8b1e8a223
commit 56a0f369cb
2 changed files with 14 additions and 3 deletions

View file

@ -2795,8 +2795,6 @@ int game_lua_kernel::intf_match_location(lua_State *L)
*/
int game_lua_kernel::intf_match_side(lua_State *L)
{
unsigned side = luaL_checkinteger(L, 1) - 1;
if (side >= teams().size()) return 0;
vconfig filter = luaW_checkvconfig(L, 2, true);
if (filter.null()) {
@ -2806,7 +2804,14 @@ int game_lua_kernel::intf_match_side(lua_State *L)
filter_context & fc = game_state_;
side_filter s_filter(filter, &fc);
lua_pushboolean(L, s_filter.match(side + 1));
if(team* t = luaW_toteam(L, 1)) {
lua_pushboolean(L, s_filter.match(*t));
} else {
unsigned side = luaL_checkinteger(L, 1) - 1;
if (side >= teams().size()) return 0;
lua_pushboolean(L, s_filter.match(side + 1));
}
return 1;
}

View file

@ -92,6 +92,9 @@ static int impl_side_get(lua_State *L)
}
return_cfg_attrib("__cfg", t.write(cfg));
if(luaW_getmetafield(L, 1, m)) {
return 1;
}
return 0;
}
@ -178,6 +181,9 @@ namespace lua_team {
lua_pushstring(L, "side");
lua_setfield(L, -2, "__metatable");
// Side methods
luaW_getglobal(L, "wesnoth", "match_side");
lua_setfield(L, -2, "matches");
return "Adding getside metatable...\n";
}