45 char const *m = luaL_checkstring(L, 2);
65 if (strcmp(m,
"traits") == 0) {
68 const std::string&
id = trait[
"id"];
69 lua_pushlstring(L,
id.c_str(),
id.length());
75 if (strcmp(m,
"abilities") == 0) {
79 if (strcmp(m,
"attacks") == 0) {
84 if(strcmp(m,
"variations") == 0) {
96 lua_pushboolean(L, &ut1 == ut2);
98 lua_pushboolean(L,
false);
105 std::string
id = luaL_checkstring(L, 2);
108 if(
id ==
"male" ||
id ==
"female") {
127 lua_pushstring(L,
"unit_types table is read-only");
142 if(lua_isnoneornil(L, 2)) {
145 lua_pushstring(L,
"male");
149 lua_pushstring(L,
"female");
156 const std::string
id = luaL_checkstring(L, 2);
159 lua_pushstring(L,
"female");
162 }
else if(
id ==
"male" ||
id ==
"female") {
177 lua_pushlstring(L, it->first.c_str(), it->first.size());
184 lua_pushvalue(L, -2);
195 std::ostringstream str;
197 str <<
"unit type: <" << ut.
id() <<
'>';
209 lua_setfield(L, -2,
"__index");
211 lua_setfield(L, -2,
"__tostring");
213 lua_setfield(L, -2,
"__eq");
215 lua_setfield(L, -2,
"__metatable");
217 return "Adding unit type metatable...\n";
222 lua_getglobal(L,
"wesnoth");
226 lua_setfield(L, -2,
"__index");
228 lua_setfield(L, -2,
"__newindex");
230 lua_setfield(L, -2,
"__len");
232 lua_setfield(L, -2,
"__pairs");
234 lua_setfield(L, -2,
"__metatable");
235 lua_setmetatable(L, -2);
236 lua_setfield(L, -2,
"unit_types");
239 return "Adding unit_types table...\n";
251 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.
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