44 char const *m = luaL_checkstring(L, 2);
64 if (strcmp(m,
"traits") == 0) {
67 const std::string&
id = trait[
"id"];
68 lua_pushlstring(L,
id.c_str(),
id.length());
74 if (strcmp(m,
"abilities") == 0) {
78 if (strcmp(m,
"attacks") == 0) {
83 if(strcmp(m,
"variations") == 0) {
95 lua_pushboolean(L, &ut1 == ut2);
97 lua_pushboolean(L,
false);
104 std::string
id = luaL_checkstring(L, 2);
107 if(
id ==
"male" ||
id ==
"female") {
126 lua_pushstring(L,
"unit_types table is read-only");
141 if(lua_isnoneornil(L, 2)) {
144 lua_pushstring(L,
"male");
148 lua_pushstring(L,
"female");
155 const std::string
id = luaL_checkstring(L, 2);
158 lua_pushstring(L,
"female");
161 }
else if(
id ==
"male" ||
id ==
"female") {
176 lua_pushlstring(L, it->first.c_str(), it->first.size());
187 lua_pushvalue(L, -2);
198 std::ostringstream str;
200 str <<
"unit type: <" << ut.
id() <<
'>';
212 lua_setfield(L, -2,
"__index");
214 lua_setfield(L, -2,
"__tostring");
216 lua_setfield(L, -2,
"__eq");
218 lua_setfield(L, -2,
"__metatable");
220 return "Adding unit type metatable...\n";
225 lua_getglobal(L,
"wesnoth");
229 lua_setfield(L, -2,
"__index");
231 lua_setfield(L, -2,
"__newindex");
233 lua_setfield(L, -2,
"__len");
235 lua_setfield(L, -2,
"__pairs");
237 lua_setfield(L, -2,
"__metatable");
238 lua_setmetatable(L, -2);
239 lua_setfield(L, -2,
"unit_types");
242 return "Adding unit_types table...\n";
254 if(
void*
p = luaL_testudata(L, idx,
UnitType)) {
A config object defines a single node in a WML file, with access to child nodes.
Container associating units to locations.
unit_iterator find(std::size_t id)
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
void build_unit_type(const unit_type &ut, unit_type::BUILD_STATUS status) const
Makes sure the provided unit_type is built to the specified level.
const unit_type_map & types() const
A single unit type that the player may recruit.
const std::vector< std::string > advances_from() const
A vector of unit_type ids that can advance to this unit_type.
std::string race_id() const
Returns the ID of this type's race without the need to build the type.
const std::string & image() const
const std::string & id() const
The id for this unit_type.
const unit_type & get_variation(const std::string &id) const
const std::vector< std::string > & advances_to() const
A vector of unit_type ids that this unit_type can advance to.
const variations_map & variation_types() const
bool has_gender_variation(const unit_race::GENDER gender) const
const unit_type & get_gender_unit_type(std::string gender) const
Returns a gendered variant of this unit_type.
const std::string & icon() const
int experience_needed(bool with_acceleration=true) const
const std::string & big_profile() const
std::vector< std::string > get_ability_list() const
const t_string & type_name() const
The name of the unit in the current language setting.
config::const_child_itors possible_traits() const
unit_alignments::type alignment() const
const std::string & small_profile() const
const config & get_cfg() const
void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
#define return_vector_string_attrib(name, accessor)
#define return_string_attrib(name, accessor)
#define return_cfgref_attrib(name, accessor)
#define return_int_attrib(name, accessor)
#define return_tstring_attrib(name, accessor)
void push_unit_attacks_table(lua_State *L, int idx)
static int impl_unit_type_lookup(lua_State *L)
static int impl_unit_type_tostring(lua_State *L)
Turns a lua proxy unit type to string.
static int impl_unit_type_next(lua_State *L)
const unit_type * luaW_tounittype(lua_State *L, int idx)
Test if a stack element is a unit type, and return it if so.
static int impl_unit_type_new(lua_State *L)
static int impl_unit_type_get(lua_State *L)
Gets some data on a unit type (__index metamethod).
static int impl_unit_type_equal(lua_State *L)
const unit_type & luaW_checkunittype(lua_State *L, int idx)
Test if a stack element is a unit type, and return it if so.
static const char UnitType[]
Implementation for a lua reference to a unit_type.
static int impl_unit_type_count(lua_State *L)
void luaW_pushunittype(lua_State *L, const unit_type &ut)
Create a lua object containing a reference to a unittype, and a metatable to access the properties.
static const char UnitTypeTable[]
static int impl_unit_type_pairs(lua_State *L)
This namespace contains bindings for lua to hold a reference to a unit type and access its stats.
std::string register_metatable(lua_State *L)
std::string register_table(lua_State *L)
void lua_push(lua_State *L, const T &val)
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
unit_type_data unit_types