Skip to content

Commit

Permalink
Add matches function to Lua unit attacks table
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Sep 11, 2016
1 parent c621c95 commit 2f5b956
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/scripting/lua_unit_attacks.cpp
Expand Up @@ -257,6 +257,9 @@ static int impl_unit_attack_get(lua_State *L)
return_int_attrib("parry", attack.parry());
return_cfgref_attrib("specials", attack.specials());
return_cfgref_attrib("__cfg", attack.to_config());
if(luaW_getmetafield(L, 1, m)) {
return 1;
}
std::string err_msg = "unknown property of attack: ";
err_msg += m;
return luaL_argerror(L, 2, err_msg.c_str());
Expand Down Expand Up @@ -303,6 +306,14 @@ static int impl_unit_attack_equal(lua_State* L)
return 1;
}

static int impl_unit_attack_match(lua_State* L)
{
const_attack_ptr atk = luaW_toweapon(L, 1);
config cfg = luaW_checkconfig(L, 2);
lua_pushboolean(L, atk->matches_filter(cfg));
return 1;
}

static int impl_unit_attack_collect(lua_State* L)
{
attack_ref* atk = static_cast<attack_ref*>(luaL_checkudata(L, 1, uattackKey));
Expand Down Expand Up @@ -342,6 +353,8 @@ namespace lua_units {
lua_setfield(L, -2, "__gc");
lua_pushstring(L, uattackKey);
lua_setfield(L, -2, "__metatable");
lua_pushcfunction(L, impl_unit_attack_match);
lua_setfield(L, -2, "matches");

return cmd_out.str();
}
Expand Down

0 comments on commit 2f5b956

Please sign in to comment.