The Battle for Wesnoth  1.15.1+dev
Namespaces | Macros | Enumerations | Functions | Variables
lua_unit.cpp File Reference
#include "scripting/lua_unit.hpp"
#include "formatter.hpp"
#include "game_board.hpp"
#include "log.hpp"
#include "map/location.hpp"
#include "map/map.hpp"
#include "resources.hpp"
#include "scripting/lua_common.hpp"
#include "scripting/lua_unit_attacks.hpp"
#include "scripting/push_check.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "units/unit.hpp"
#include "units/map.hpp"
#include "units/animation_component.hpp"
#include "lua/lauxlib.h"
#include "lua/lua.h"
Include dependency graph for lua_unit.cpp:

Go to the source code of this file.

Namespaces

 lua_units
 

Macros

#define LOG_LUA   LOG_STREAM(info, log_scripting_lua)
 
#define ERR_LUA   LOG_STREAM(err, log_scripting_lua)
 

Enumerations

enum  { LU_OK, LU_NOT_UNIT, LU_NOT_ON_MAP, LU_NOT_VALID }
 

Functions

bool luaW_isunit (lua_State *L, int index)
 Test if a Lua value is a unit. More...
 
static lua_unitinternal_get_unit (lua_State *L, int index, bool only_on_map, int &error)
 
unitluaW_tounit (lua_State *L, int index, bool only_on_map)
 Converts a Lua value to a unit pointer. More...
 
unit_ptr luaW_tounit_ptr (lua_State *L, int index, bool only_on_map)
 Similar to luaW_tounit but returns a unit_ptr; use this instead of luaW_tounit when using an api that needs unit_ptr. More...
 
lua_unitluaW_tounit_ref (lua_State *L, int index)
 Similar to luaW_tounit but returns a lua_unit; use this if you need to handle map and recall units differently, for example. More...
 
static void unit_show_error (lua_State *L, int index, int error)
 
unit_ptr luaW_checkunit_ptr (lua_State *L, int index, bool only_on_map)
 Similar to luaW_checkunit but returns a unit_ptr; use this instead of luaW_checkunit when using an api that needs unit_ptr. More...
 
unitluaW_checkunit (lua_State *L, int index, bool only_on_map)
 Converts a Lua value to a unit pointer. More...
 
lua_unitluaW_checkunit_ref (lua_State *L, int index)
 Similar to luaW_checkunit but returns a lua_unit; use this if you need to handle map and recall units differently, for example. More...
 
lua_unitluaW_pushlocalunit (lua_State *L, unit &u)
 Pushes a private unit on the stack. More...
 
static int impl_unit_collect (lua_State *L)
 Destroys a unit object before it is collected (__gc metamethod). More...
 
static int impl_unit_equality (lua_State *L)
 Checks two lua proxy units for equality. More...
 
static int impl_unit_get (lua_State *L)
 Gets some data on a unit (__index metamethod). More...
 
static int impl_unit_set (lua_State *L)
 Sets some data on a unit (__newindex metamethod). More...
 
static int impl_unit_status_get (lua_State *L)
 Gets the status of a unit (__index metamethod). More...
 
static int impl_unit_status_set (lua_State *L)
 Sets the status of a unit (__newindex metamethod). More...
 
static int impl_unit_variables_get (lua_State *L)
 Gets the variable of a unit (__index metamethod). More...
 
static int impl_unit_variables_set (lua_State *L)
 Sets the variable of a unit (__newindex metamethod). More...
 
std::string lua_units::register_metatables (lua_State *L)
 

Variables

static lg::log_domain log_scripting_lua ("scripting/lua")
 
static const char getunitKey [] = "unit"
 
static const char ustatusKey [] = "unit status"
 
static const char unitvarKey [] = "unit variables"
 

Macro Definition Documentation

◆ ERR_LUA

#define ERR_LUA   LOG_STREAM(err, log_scripting_lua)

Definition at line 36 of file lua_unit.cpp.

Referenced by lua_unit::put_map().

◆ LOG_LUA

#define LOG_LUA   LOG_STREAM(info, log_scripting_lua)

Definition at line 35 of file lua_unit.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
LU_OK 
LU_NOT_UNIT 
LU_NOT_ON_MAP 
LU_NOT_VALID 

Definition at line 119 of file lua_unit.cpp.

Function Documentation

◆ impl_unit_collect()

static int impl_unit_collect ( lua_State L)
static

Destroys a unit object before it is collected (__gc metamethod).

Definition at line 223 of file lua_unit.cpp.

References lua_touserdata().

Referenced by lua_units::register_metatables().

◆ impl_unit_equality()

static int impl_unit_equality ( lua_State L)
static

Checks two lua proxy units for equality.

(__eq metamethod)

Definition at line 233 of file lua_unit.cpp.

References left, lua_pushboolean(), luaW_checkunit(), right, and unit::underlying_id().

Referenced by lua_units::register_metatables().

◆ impl_unit_get()

static int impl_unit_get ( lua_State L)
static

Gets some data on a unit (__index metamethod).

  • Arg 1: full userdata containing the unit id.
  • Arg 2: string containing the name of the property.
  • Ret 1: something containing the attribute.

Definition at line 248 of file lua_unit.cpp.

References unit::absolute_image(), unit::advances_to(), unit::alignment(), unit::anim_comp(), variable_info_implementation::apply_visitor(), unit::attacks_left(), unit::big_profile(), unit::can_recruit(), unit::cost(), unit::effect_image_mods(), unit::experience(), unit::facing(), unit::gender(), gender_string(), unit::get_ability_list(), unit::get_emit_zoc(), unit_animation_component::get_flags(), unit::get_goto(), unit::get_hidden(), unit::get_location(), unit::get_role(), unit::get_traits_list(), unit::hitpoints(), unit_race::id(), unit::id(), unit::image_mods(), unit::incapacitated(), unit::level(), lua_createtable(), lua_push(), lua_pushinteger(), lua_pushstring(), lua_pushvalue(), lua_rawseti(), lua_touserdata(), luaL_argerror(), luaL_checkstring, luaL_setmetatable(), luaW_getmetafield(), unit::max_attacks(), unit::max_experience(), unit::max_hitpoints(), unit::modification_advancements(), unit::movement_left(), unit::name(), unit::overlays(), push_unit_attacks_table(), unit::race(), unit::recall_cost(), unit::recall_filter(), unit::recruits(), unit::resting(), return_bool_attrib, return_cfg_attrib, return_int_attrib, return_string_attrib, return_tstring_attrib, return_vector_string_attrib, unit::side(), unit::total_movement(), unit::type_id(), unitvarKey, unit::upkeep_raw(), unit::usage(), ustatusKey, unit::variation(), map_location::wml_x(), map_location::wml_y(), map_location::write(), unit::write(), and map_location::write_direction().

Referenced by lua_units::register_metatables().

◆ impl_unit_set()

static int impl_unit_set ( lua_State L)
static

◆ impl_unit_status_get()

static int impl_unit_status_get ( lua_State L)
static

Gets the status of a unit (__index metamethod).

  • Arg 1: table containing the userdata containing the unit id.
  • Arg 2: string containing the name of the status.
  • Ret 1: boolean.

Definition at line 517 of file lua_unit.cpp.

References unit::get_state(), lua_istable, lua_pushboolean(), lua_rawgeti(), luaL_argerror(), luaL_checkstring, luaW_tounit(), and luaW_type_error().

Referenced by lua_units::register_metatables().

◆ impl_unit_status_set()

static int impl_unit_status_set ( lua_State L)
static

Sets the status of a unit (__newindex metamethod).

  • Arg 1: table containing the userdata containing the unit id.
  • Arg 2: string containing the name of the status.
  • Arg 3: boolean.

Definition at line 538 of file lua_unit.cpp.

References lua_istable, lua_rawgeti(), luaL_argerror(), luaL_checkstring, luaW_toboolean(), luaW_tounit(), luaW_type_error(), and unit::set_state().

Referenced by lua_units::register_metatables().

◆ impl_unit_variables_get()

static int impl_unit_variables_get ( lua_State L)
static

Gets the variable of a unit (__index metamethod).

  • Arg 1: table containing the userdata containing the unit id.
  • Arg 2: string containing the name of the status.
  • Ret 1: boolean.

Definition at line 559 of file lua_unit.cpp.

References lua_istable, lua_rawgeti(), luaL_argerror(), luaL_checkstring, luaW_pushvariable(), luaW_tounit(), luaW_type_error(), return_cfgref_attrib, and unit::variables().

Referenced by lua_units::register_metatables().

◆ impl_unit_variables_set()

static int impl_unit_variables_set ( lua_State L)
static

Sets the variable of a unit (__newindex metamethod).

  • Arg 1: table containing the userdata containing the unit id.
  • Arg 2: string containing the name of the status.
  • Arg 3: scalar.

Definition at line 582 of file lua_unit.cpp.

References lua_isnoneornil, lua_istable, lua_rawgeti(), luaL_argerror(), luaL_checkstring, luaW_checkconfig(), luaW_checkvariable(), luaW_tounit(), luaW_type_error(), and unit::variables().

Referenced by lua_units::register_metatables().

◆ internal_get_unit()

static lua_unit* internal_get_unit ( lua_State L,
int  index,
bool  only_on_map,
int &  error 
)
static

◆ luaW_checkunit()

unit& luaW_checkunit ( lua_State L,
int  index,
bool  only_on_map 
)

◆ luaW_checkunit_ptr()

unit_ptr luaW_checkunit_ptr ( lua_State L,
int  index,
bool  only_on_map 
)

Similar to luaW_checkunit but returns a unit_ptr; use this instead of luaW_checkunit when using an api that needs unit_ptr.

Definition at line 184 of file lua_unit.cpp.

References error(), internal_get_unit(), and unit_show_error().

Referenced by game_lua_kernel::intf_find_vacant_tile(), and game_lua_kernel::intf_teleport().

◆ luaW_checkunit_ref()

lua_unit* luaW_checkunit_ref ( lua_State L,
int  index 
)

Similar to luaW_checkunit but returns a lua_unit; use this if you need to handle map and recall units differently, for example.

Definition at line 200 of file lua_unit.cpp.

References error(), internal_get_unit(), and unit_show_error().

Referenced by game_lua_kernel::intf_erase_unit(), game_lua_kernel::intf_extract_unit(), game_lua_kernel::intf_match_unit(), game_lua_kernel::intf_put_recall_unit(), and game_lua_kernel::intf_put_unit().

◆ luaW_isunit()

bool luaW_isunit ( lua_State L,
int  index 
)

◆ luaW_pushlocalunit()

lua_unit* luaW_pushlocalunit ( lua_State L,
unit u 
)

Pushes a private unit on the stack.

Definition at line 213 of file lua_unit.cpp.

References lua_unit::lua_unit(), and lua_unit::setmetatable().

Referenced by game_lua_kernel::apply_effect(), and game_lua_kernel::run_filter().

◆ luaW_tounit()

unit* luaW_tounit ( lua_State L,
int  index,
bool  only_on_map 
)

◆ luaW_tounit_ptr()

unit_ptr luaW_tounit_ptr ( lua_State L,
int  index,
bool  only_on_map 
)

Similar to luaW_tounit but returns a unit_ptr; use this instead of luaW_tounit when using an api that needs unit_ptr.

Definition at line 153 of file lua_unit.cpp.

References error(), internal_get_unit(), and LU_OK.

◆ luaW_tounit_ref()

lua_unit* luaW_tounit_ref ( lua_State L,
int  index 
)

Similar to luaW_tounit but returns a lua_unit; use this if you need to handle map and recall units differently, for example.

Note that this only returns null if the element on the stack was not a unit, so it may be an invalid unit.

Definition at line 163 of file lua_unit.cpp.

References error(), and internal_get_unit().

Referenced by impl_unit_attacks_get().

◆ unit_show_error()

static void unit_show_error ( lua_State L,
int  index,
int  error 
)
static

Variable Documentation

◆ getunitKey

const char getunitKey[] = "unit"
static

◆ log_scripting_lua

lg::log_domain log_scripting_lua("scripting/lua")
static

◆ unitvarKey

const char unitvarKey[] = "unit variables"
static

Definition at line 40 of file lua_unit.cpp.

Referenced by impl_unit_get(), and lua_units::register_metatables().

◆ ustatusKey

const char ustatusKey[] = "unit status"
static

Definition at line 39 of file lua_unit.cpp.

Referenced by impl_unit_get(), and lua_units::register_metatables().