The Battle for Wesnoth  1.19.5+dev
Classes | Namespaces | Typedefs | Functions | Variables
lua_unit_attacks.cpp File Reference
#include "scripting/lua_unit_attacks.hpp"
#include "scripting/lua_common.hpp"
#include "scripting/lua_unit.hpp"
#include "scripting/lua_unit_type.hpp"
#include "scripting/push_check.hpp"
#include "units/unit.hpp"
#include "units/types.hpp"
#include "units/attack_type.hpp"
#include "utils/const_clone.hpp"
#include <type_traits>
Include dependency graph for lua_unit_attacks.cpp:

Go to the source code of this file.

Classes

struct  attack_ref
 

Namespaces

 lua_units
 

Typedefs

template<typename T >
using attack_ptr_in = std::shared_ptr< utils::const_clone_t< attack_type, std::remove_pointer_t< T > >>
 

Functions

void push_unit_attacks_table (lua_State *L, int idx)
 
void luaW_pushweapon (lua_State *L, attack_ptr weapon)
 
void luaW_pushweapon (lua_State *L, const_attack_ptr weapon)
 
static attack_refluaW_checkweapon_ref (lua_State *L, int idx)
 
const_attack_ptr luaW_toweapon (lua_State *L, int idx)
 
attack_typeluaW_checkweapon (lua_State *L, int idx)
 
template<typename T >
auto find_attack (T *u, const std::string &id) -> attack_ptr_in< T >
 
template<typename T >
auto find_attack (T *u, std::size_t i) -> attack_ptr_in< T >
 
static int impl_unit_attacks_get (lua_State *L)
 Gets the attacks of a unit or unit type (__index metamethod). More...
 
static attack_itors::iterator get_attack_iter (unit &u, attack_ptr atk)
 
static int impl_unit_attacks_set (lua_State *L)
 
static int impl_unit_attacks_len (lua_State *L)
 Counts the attacks of a unit (__len metamethod). More...
 
static int impl_unit_attacks_next (lua_State *L)
 
static int impl_unit_attacks_iter (lua_State *L)
 
static int impl_unit_attack_get (lua_State *L)
 Gets a property of a units attack (__index metamethod). More...
 
static int impl_unit_attack_set (lua_State *L)
 Gets a property of a units attack (__index metamethod). More...
 
static int impl_unit_attack_equal (lua_State *L)
 
static int impl_unit_attack_tostring (lua_State *L)
 Turns a lua proxy attack to string. More...
 
static int impl_unit_attack_match (lua_State *L)
 
static int impl_unit_attack_collect (lua_State *L)
 
int intf_create_attack (lua_State *L)
 
std::string lua_units::register_attacks_metatables (lua_State *L)
 

Variables

static const char uattacksKey [] = "unit attacks table"
 
static const char uattackKey [] = "unit attack"
 

Typedef Documentation

◆ attack_ptr_in

template<typename T >
using attack_ptr_in = std::shared_ptr<utils::const_clone_t<attack_type, std::remove_pointer_t<T> >>

Definition at line 93 of file lua_unit_attacks.cpp.

Function Documentation

◆ find_attack() [1/2]

template<typename T >
auto find_attack ( T *  u,
const std::string &  id 
) -> attack_ptr_in<T>

Definition at line 97 of file lua_unit_attacks.cpp.

References schema_validation::at().

Referenced by impl_unit_attacks_get(), and impl_unit_attacks_set().

◆ find_attack() [2/2]

template<typename T >
auto find_attack ( T *  u,
std::size_t  i 
) -> attack_ptr_in<T>

Definition at line 109 of file lua_unit_attacks.cpp.

References i.

◆ get_attack_iter()

static attack_itors::iterator get_attack_iter ( unit u,
attack_ptr  atk 
)
static

Definition at line 147 of file lua_unit_attacks.cpp.

References unit::attacks().

Referenced by impl_unit_attacks_set().

◆ impl_unit_attack_collect()

static int impl_unit_attack_collect ( lua_State *  L)
static

Definition at line 349 of file lua_unit_attacks.cpp.

References uattackKey.

Referenced by lua_units::register_attacks_metatables().

◆ impl_unit_attack_equal()

static int impl_unit_attack_equal ( lua_State *  L)
static

Definition at line 318 of file lua_unit_attacks.cpp.

References luaW_toweapon().

Referenced by lua_units::register_attacks_metatables().

◆ impl_unit_attack_get()

static int impl_unit_attack_get ( lua_State *  L)
static

◆ impl_unit_attack_match()

static int impl_unit_attack_match ( lua_State *  L)
static

Definition at line 338 of file lua_unit_attacks.cpp.

References luaW_checkconfig(), and luaW_toweapon().

Referenced by lua_units::register_attacks_metatables().

◆ impl_unit_attack_set()

static int impl_unit_attack_set ( lua_State *  L)
static

◆ impl_unit_attack_tostring()

static int impl_unit_attack_tostring ( lua_State *  L)
static

Turns a lua proxy attack to string.

(__tostring metamethod)

Definition at line 329 of file lua_unit_attacks.cpp.

References attack_ref::cattack, lua_push(), and luaW_checkweapon_ref().

Referenced by lua_units::register_attacks_metatables().

◆ impl_unit_attacks_get()

static int impl_unit_attacks_get ( lua_State *  L)
static

Gets the attacks of a unit or unit type (__index metamethod).

  • Arg 1: table containing the userdata containing the unit or unit type.
  • Arg 2: index (int) or id (string) identifying a particular attack.
  • Ret 1: the unit's attacks.

Definition at line 126 of file lua_unit_attacks.cpp.

References find_attack(), luaW_pushweapon(), luaW_tounit_ref(), luaW_tounittype(), and luaW_type_error().

Referenced by lua_units::register_attacks_metatables().

◆ impl_unit_attacks_iter()

static int impl_unit_attacks_iter ( lua_State *  L)
static

Definition at line 235 of file lua_unit_attacks.cpp.

References impl_unit_attacks_next().

Referenced by lua_units::register_attacks_metatables().

◆ impl_unit_attacks_len()

static int impl_unit_attacks_len ( lua_State *  L)
static

Counts the attacks of a unit (__len metamethod).

  • Arg 1: table containing the userdata containing the unit id.
  • Ret 1: size of unit attacks vector.

Definition at line 206 of file lua_unit_attacks.cpp.

References unit::attacks(), unit_type::attacks(), luaW_tounit(), luaW_tounittype(), and luaW_type_error().

Referenced by lua_units::register_attacks_metatables().

◆ impl_unit_attacks_next()

static int impl_unit_attacks_next ( lua_State *  L)
static

Definition at line 221 of file lua_unit_attacks.cpp.

References n.

Referenced by impl_unit_attacks_iter().

◆ impl_unit_attacks_set()

static int impl_unit_attacks_set ( lua_State *  L)
static

◆ intf_create_attack()

int intf_create_attack ( lua_State *  L)

Definition at line 356 of file lua_unit_attacks.cpp.

References luaW_checkconfig(), and luaW_pushweapon().

Referenced by game_lua_kernel::game_lua_kernel().

◆ luaW_checkweapon()

attack_type& luaW_checkweapon ( lua_State *  L,
int  idx 
)

Definition at line 83 of file lua_unit_attacks.cpp.

References attack_ref::attack, and luaW_checkweapon_ref().

Referenced by impl_unit_attack_set().

◆ luaW_checkweapon_ref()

static attack_ref& luaW_checkweapon_ref ( lua_State *  L,
int  idx 
)
static

Definition at line 70 of file lua_unit_attacks.cpp.

References uattackKey.

Referenced by impl_unit_attack_get(), impl_unit_attack_tostring(), and luaW_checkweapon().

◆ luaW_pushweapon() [1/2]

void luaW_pushweapon ( lua_State *  L,
attack_ptr  weapon 
)

◆ luaW_pushweapon() [2/2]

void luaW_pushweapon ( lua_State *  L,
const_attack_ptr  weapon 
)

Definition at line 60 of file lua_unit_attacks.cpp.

References uattackKey.

◆ luaW_toweapon()

const_attack_ptr luaW_toweapon ( lua_State *  L,
int  idx 
)

◆ push_unit_attacks_table()

void push_unit_attacks_table ( lua_State *  L,
int  idx 
)

Definition at line 40 of file lua_unit_attacks.cpp.

References uattacksKey.

Referenced by UNIT_GETTER(), and UNIT_TYPE_GETTER().

Variable Documentation

◆ uattackKey

const char uattackKey[] = "unit attack"
static

◆ uattacksKey

const char uattacksKey[] = "unit attacks table"
static