The Battle for Wesnoth  1.15.2+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 "game_version.hpp"
#include "deprecation.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_tostring (lua_State *L)
 Turns a lua proxy unit to string. 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 38 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 37 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 121 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 225 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 235 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 276 of file lua_unit.cpp.

Referenced by lua_units::register_metatables().

◆ impl_unit_set()

static int impl_unit_set ( lua_State L)
static

Sets some data on a unit (__newindex metamethod).

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

Definition at line 426 of file lua_unit.cpp.

References luaL_argerror(), and luaW_checklocation().

Referenced by lua_units::register_metatables().

◆ 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 565 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 586 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_tostring()

static int impl_unit_tostring ( lua_State L)
static

Turns a lua proxy unit to string.

(__tostring metamethod)

Definition at line 247 of file lua_unit.cpp.

References unit::get_location(), unit::id(), luaW_tounit_ref(), lua_unit::side, and unit::type_id().

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 607 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 630 of file lua_unit.cpp.

References lua_isnoneornil, lua_istable, lua_rawgeti(), luaL_argerror(), luaL_checkstring, luaW_checkvariable(), luaW_tounit(), luaW_type_error(), modify_cfg_attrib, 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 186 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 202 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 215 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 155 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 165 of file lua_unit.cpp.

References error(), and internal_get_unit().

Referenced by impl_unit_attacks_get(), and impl_unit_tostring().

◆ 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 42 of file lua_unit.cpp.

Referenced by lua_units::register_metatables().

◆ ustatusKey

const char ustatusKey[] = "unit status"
static

Definition at line 41 of file lua_unit.cpp.

Referenced by lua_units::register_metatables().