Skip to content

Commit

Permalink
Enable #wesnoth.unit_types and #wesnoth.unit_types[type].variations
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Sep 29, 2016
1 parent b563d8d commit d944f41
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/scripting/lua_unit_type.cpp
Expand Up @@ -122,6 +122,18 @@ static int impl_unit_type_new(lua_State* L)
return lua_error(L);
}

static int impl_unit_type_count(lua_State* L)
{
lua_pushstring(L, "base");
lua_rawget(L, 1);
if(const unit_type* base = luaW_tounittype(L, -1)) {
lua_pushnumber(L, base->variations().size() + base->genders().size());
} else {
lua_pushnumber(L, unit_types.types().size());
}
return 1;
}

static int impl_unit_type_next(lua_State* L)
{
const unit_type* base = *static_cast<const unit_type**>(luaL_testudata(L, 1, UnitTypeTable));
Expand Down Expand Up @@ -198,6 +210,8 @@ namespace lua_unit_type {
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, impl_unit_type_new);
lua_setfield(L, -2, "__newindex");
lua_pushcfunction(L, impl_unit_type_count);
lua_setfield(L, -2, "__len");
lua_pushcfunction(L, impl_unit_type_pairs);
lua_setfield(L, -2, "__pairs");
lua_pushstring(L, UnitTypeTable);
Expand Down

0 comments on commit d944f41

Please sign in to comment.