The Battle for Wesnoth  1.19.7+dev
Classes | Namespaces | Macros | Typedefs | Functions | Variables
lua_unit_type.cpp File Reference
#include "scripting/lua_unit_type.hpp"
#include "scripting/lua_attributes.hpp"
#include "scripting/lua_common.hpp"
#include "scripting/lua_unit_attacks.hpp"
#include "scripting/push_check.hpp"
#include "units/types.hpp"
#include <string>
#include <cstring>
Include dependency graph for lua_unit_type.cpp:

Go to the source code of this file.

Classes

struct  lua_object_traits< unit_type >
 

Namespaces

 lua_unit_type
 This namespace contains bindings for lua to hold a reference to a unit type and access its stats.
 

Macros

#define UNIT_TYPE_GETTER(name, type)   LATTR_GETTER(name, type, unit_type, ut)
 
#define UNIT_TYPE_VALID(name)   LATTR_VALID(name, unit_type, ut)
 

Typedefs

using traits_map = std::map< std::string, config >
 

Functions

 UNIT_TYPE_GETTER ("name", t_string)
 
 UNIT_TYPE_GETTER ("id", std::string)
 
 UNIT_TYPE_GETTER ("alignment", std::string)
 
 UNIT_TYPE_GETTER ("race", std::string)
 
 UNIT_TYPE_GETTER ("image", std::string)
 
 UNIT_TYPE_GETTER ("icon", std::string)
 
 UNIT_TYPE_GETTER ("profile", std::string)
 
 UNIT_TYPE_GETTER ("small_profile", std::string)
 
 UNIT_TYPE_GETTER ("max_hitpoints", int)
 
 UNIT_TYPE_GETTER ("max_moves", int)
 
 UNIT_TYPE_GETTER ("max_experience", int)
 
 UNIT_TYPE_GETTER ("cost", int)
 
 UNIT_TYPE_GETTER ("level", int)
 
 UNIT_TYPE_GETTER ("recall_cost", int)
 
 UNIT_TYPE_GETTER ("advances_to", std::vector< std::string >)
 
 UNIT_TYPE_GETTER ("advances_from", std::vector< std::string >)
 
 UNIT_TYPE_GETTER ("__cfg", config)
 
 UNIT_TYPE_GETTER ("traits", traits_map)
 
 UNIT_TYPE_GETTER ("abilities", std::vector< std::string >)
 
 UNIT_TYPE_GETTER ("attacks", lua_index_raw)
 
 UNIT_TYPE_VALID ("variations")
 
 UNIT_TYPE_GETTER ("variations", lua_index_raw)
 
static int impl_unit_type_get (lua_State *L)
 Gets some data on a unit type (__index metamethod). More...
 
static int impl_unit_type_dir (lua_State *L)
 Gets a list of data on a unit type (__dir metamethod). More...
 
static int impl_unit_type_equal (lua_State *L)
 
static int impl_unit_type_list (lua_State *L)
 
static int impl_unit_type_lookup (lua_State *L)
 
static int impl_unit_type_new (lua_State *L)
 
static int impl_unit_type_count (lua_State *L)
 
static int impl_unit_type_next (lua_State *L)
 
static int impl_unit_type_pairs (lua_State *L)
 
static int impl_unit_type_tostring (lua_State *L)
 Turns a lua proxy unit type to string. More...
 
std::string lua_unit_type::register_metatable (lua_State *L)
 
std::string lua_unit_type::register_table (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. More...
 
const unit_typeluaW_tounittype (lua_State *L, int idx)
 Test if a stack element is a unit type, and return it if so. More...
 
const unit_typeluaW_checkunittype (lua_State *L, int idx)
 Test if a stack element is a unit type, and return it if so. More...
 

Variables

static const char UnitType [] = "unit type"
 Implementation for a lua reference to a unit_type. More...
 
static const char UnitTypeTable [] = "unit types"
 
luaW_Registry unitTypeReg {UnitType}
 

Macro Definition Documentation

◆ UNIT_TYPE_GETTER

#define UNIT_TYPE_GETTER (   name,
  type 
)    LATTR_GETTER(name, type, unit_type, ut)

Definition at line 36 of file lua_unit_type.cpp.

◆ UNIT_TYPE_VALID

#define UNIT_TYPE_VALID (   name)    LATTR_VALID(name, unit_type, ut)

Definition at line 37 of file lua_unit_type.cpp.

Typedef Documentation

◆ traits_map

using traits_map = std::map<std::string,config>

Definition at line 115 of file lua_unit_type.cpp.

Function Documentation

◆ impl_unit_type_count()

static int impl_unit_type_count ( lua_State *  L)
static

Definition at line 224 of file lua_unit_type.cpp.

References unit_type_data::types(), and unit_types.

Referenced by lua_unit_type::register_table().

◆ impl_unit_type_dir()

static int impl_unit_type_dir ( lua_State *  L)
static

Gets a list of data on a unit type (__dir metamethod).

  • Ret 1: a list of attributes.

Definition at line 160 of file lua_unit_type.cpp.

References luaW_Registry::dir(), and unitTypeReg.

Referenced by lua_unit_type::register_metatable().

◆ impl_unit_type_equal()

static int impl_unit_type_equal ( lua_State *  L)
static

Definition at line 165 of file lua_unit_type.cpp.

References luaW_checkunittype(), and luaW_tounittype().

Referenced by lua_unit_type::register_metatable().

◆ impl_unit_type_get()

static int impl_unit_type_get ( lua_State *  L)
static

Gets some data on a unit type (__index metamethod).

  • Arg 1: table containing an "id" field.
  • Arg 2: string containing the name of the property.
  • Ret 1: something containing the attribute.

Definition at line 151 of file lua_unit_type.cpp.

References luaW_Registry::get(), and unitTypeReg.

Referenced by lua_unit_type::register_metatable().

◆ impl_unit_type_list()

static int impl_unit_type_list ( lua_State *  L)
static

◆ impl_unit_type_lookup()

static int impl_unit_type_lookup ( lua_State *  L)
static

◆ impl_unit_type_new()

static int impl_unit_type_new ( lua_State *  L)
static

Definition at line 216 of file lua_unit_type.cpp.

Referenced by lua_unit_type::register_table().

◆ impl_unit_type_next()

static int impl_unit_type_next ( lua_State *  L)
static

◆ impl_unit_type_pairs()

static int impl_unit_type_pairs ( lua_State *  L)
static

Definition at line 279 of file lua_unit_type.cpp.

References impl_unit_type_next().

Referenced by lua_unit_type::register_table().

◆ impl_unit_type_tostring()

static int impl_unit_type_tostring ( lua_State *  L)
static

Turns a lua proxy unit type to string.

(__tostring metamethod)

Definition at line 289 of file lua_unit_type.cpp.

References unit_type::id(), lua_push(), and luaW_checkunittype().

Referenced by lua_unit_type::register_metatable().

◆ luaW_checkunittype()

const unit_type& luaW_checkunittype ( lua_State *  L,
int  idx 
)

Test if a stack element is a unit type, and return it if so.

Definition at line 358 of file lua_unit_type.cpp.

References UnitType.

Referenced by lua_object_traits< unit_type >::get(), impl_unit_type_equal(), and impl_unit_type_tostring().

◆ luaW_pushunittype()

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.

Definition at line 344 of file lua_unit_type.cpp.

References UnitType.

Referenced by impl_unit_type_lookup(), impl_unit_type_next(), and luaW_pushfaivariant().

◆ luaW_tounittype()

const unit_type* luaW_tounittype ( lua_State *  L,
int  idx 
)

Test if a stack element is a unit type, and return it if so.

Definition at line 350 of file lua_unit_type.cpp.

References p, and UnitType.

Referenced by impl_unit_attacks_get(), impl_unit_attacks_len(), impl_unit_attacks_set(), impl_unit_type_equal(), lua_formula_bridge::intf_eval_formula(), luaW_tofaivariant(), and WIDGET_SETTER().

◆ UNIT_TYPE_GETTER() [1/21]

UNIT_TYPE_GETTER ( "__cfg"  ,
config   
)

Definition at line 111 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [2/21]

UNIT_TYPE_GETTER ( "abilities"  ,
std::vector< std::string >   
)

Definition at line 124 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [3/21]

UNIT_TYPE_GETTER ( "advances_from"  ,
std::vector< std::string >   
)

Definition at line 107 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [4/21]

UNIT_TYPE_GETTER ( "advances_to"  ,
std::vector< std::string >   
)

Definition at line 103 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [5/21]

UNIT_TYPE_GETTER ( "alignment"  ,
std::string   
)

◆ UNIT_TYPE_GETTER() [6/21]

UNIT_TYPE_GETTER ( "attacks"  ,
lua_index_raw   
)

Definition at line 128 of file lua_unit_type.cpp.

References push_unit_attacks_table().

◆ UNIT_TYPE_GETTER() [7/21]

UNIT_TYPE_GETTER ( "cost"  ,
int   
)

Definition at line 91 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [8/21]

UNIT_TYPE_GETTER ( "icon"  ,
std::string   
)

Definition at line 67 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [9/21]

UNIT_TYPE_GETTER ( "id"  ,
std::string   
)

Definition at line 51 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [10/21]

UNIT_TYPE_GETTER ( "image"  ,
std::string   
)

Definition at line 63 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [11/21]

UNIT_TYPE_GETTER ( "level"  ,
int   
)

Definition at line 95 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [12/21]

UNIT_TYPE_GETTER ( "max_experience"  ,
int   
)

Definition at line 87 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [13/21]

UNIT_TYPE_GETTER ( "max_hitpoints"  ,
int   
)

Definition at line 79 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [14/21]

UNIT_TYPE_GETTER ( "max_moves"  ,
int   
)

Definition at line 83 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [15/21]

UNIT_TYPE_GETTER ( "name"  ,
t_string   
)

Definition at line 47 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [16/21]

UNIT_TYPE_GETTER ( "profile"  ,
std::string   
)

Definition at line 71 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [17/21]

UNIT_TYPE_GETTER ( "race"  ,
std::string   
)

Definition at line 59 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [18/21]

UNIT_TYPE_GETTER ( "recall_cost"  ,
int   
)

Definition at line 99 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [19/21]

UNIT_TYPE_GETTER ( "small_profile"  ,
std::string   
)

Definition at line 75 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [20/21]

UNIT_TYPE_GETTER ( "traits"  ,
traits_map   
)

Definition at line 116 of file lua_unit_type.cpp.

◆ UNIT_TYPE_GETTER() [21/21]

UNIT_TYPE_GETTER ( "variations"  ,
lua_index_raw   
)

Definition at line 138 of file lua_unit_type.cpp.

References UnitTypeTable.

◆ UNIT_TYPE_VALID()

UNIT_TYPE_VALID ( "variations"  )

Definition at line 134 of file lua_unit_type.cpp.

Variable Documentation

◆ UnitType

const char UnitType[] = "unit type"
static

Implementation for a lua reference to a unit_type.

Definition at line 33 of file lua_unit_type.cpp.

Referenced by luaW_checkunittype(), luaW_pushunittype(), luaW_tounittype(), and lua_unit_type::register_metatable().

◆ unitTypeReg

luaW_Registry unitTypeReg {UnitType}

Definition at line 38 of file lua_unit_type.cpp.

Referenced by impl_unit_type_dir(), and impl_unit_type_get().

◆ UnitTypeTable

const char UnitTypeTable[] = "unit types"
static