#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"
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_unit * | internal_get_unit (lua_State *L, int index, bool only_on_map, int &error) |
unit * | luaW_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_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. 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... | |
unit & | luaW_checkunit (lua_State *L, int index, bool only_on_map) |
Converts a Lua value to a unit pointer. More... | |
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. More... | |
lua_unit * | luaW_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" |
#define ERR_LUA LOG_STREAM(err, log_scripting_lua) |
Definition at line 38 of file lua_unit.cpp.
#define LOG_LUA LOG_STREAM(info, log_scripting_lua) |
Definition at line 37 of file lua_unit.cpp.
anonymous enum |
Enumerator | |
---|---|
LU_OK | |
LU_NOT_UNIT | |
LU_NOT_ON_MAP | |
LU_NOT_VALID |
Definition at line 118 of file lua_unit.cpp.
|
static |
Destroys a unit object before it is collected (__gc metamethod).
Definition at line 222 of file lua_unit.cpp.
Referenced by lua_units::register_metatables().
|
static |
Checks two lua proxy units for equality.
(__eq metamethod)
Definition at line 232 of file lua_unit.cpp.
References luaW_checkunit(), and unit::underlying_id().
Referenced by lua_units::register_metatables().
|
static |
Gets some data on a unit (__index metamethod).
Definition at line 273 of file lua_unit.cpp.
Referenced by lua_units::register_metatables().
|
static |
Sets some data on a unit (__newindex metamethod).
Definition at line 423 of file lua_unit.cpp.
Referenced by lua_units::register_metatables().
|
static |
Gets the status of a unit (__index metamethod).
Definition at line 559 of file lua_unit.cpp.
References unit::get_state(), luaW_tounit(), and luaW_type_error().
Referenced by lua_units::register_metatables().
|
static |
Sets the status of a unit (__newindex metamethod).
Definition at line 580 of file lua_unit.cpp.
References luaW_toboolean(), luaW_tounit(), luaW_type_error(), and unit::set_state().
Referenced by lua_units::register_metatables().
|
static |
Turns a lua proxy unit to string.
(__tostring metamethod)
Definition at line 244 of file lua_unit.cpp.
References unit::get_location(), unit::id(), luaW_tounit_ref(), and unit::type_id().
Referenced by lua_units::register_metatables().
|
static |
Gets the variable of a unit (__index metamethod).
Definition at line 601 of file lua_unit.cpp.
References luaW_pushvariable(), luaW_tounit(), luaW_type_error(), return_cfgref_attrib, and unit::variables().
Referenced by lua_units::register_metatables().
|
static |
Sets the variable of a unit (__newindex metamethod).
Definition at line 624 of file lua_unit.cpp.
References luaW_checkvariable(), luaW_tounit(), luaW_type_error(), modify_cfg_attrib, and unit::variables().
Referenced by lua_units::register_metatables().
|
static |
Definition at line 125 of file lua_unit.cpp.
References utf8::index(), LU_NOT_ON_MAP, LU_NOT_UNIT, LU_NOT_VALID, LU_OK, and luaW_isunit().
Referenced by luaW_checkunit(), luaW_checkunit_ptr(), luaW_checkunit_ref(), luaW_tounit(), luaW_tounit_ptr(), and luaW_tounit_ref().
unit& luaW_checkunit | ( | lua_State * | L, |
int | index, | ||
bool | only_on_map | ||
) |
Converts a Lua value to a unit pointer.
Definition at line 191 of file lua_unit.cpp.
References utf8::index(), internal_get_unit(), and unit_show_error().
Referenced by game_lua_kernel::cfun_builtin_effect(), impl_unit_attacks_set(), impl_unit_equality(), intf_add_modification(), intf_advance_unit(), intf_copy_unit(), game_lua_kernel::intf_find_path(), game_lua_kernel::intf_find_reach(), game_lua_kernel::intf_find_vision_range(), intf_remove_modifications(), game_lua_kernel::intf_simulate_combat(), intf_transform_unit(), game_lua_kernel::intf_unit_ability(), intf_unit_defense(), intf_unit_jamming_cost(), intf_unit_movement_cost(), intf_unit_resistance(), and intf_unit_vision_cost().
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 183 of file lua_unit.cpp.
References utf8::index(), internal_get_unit(), and unit_show_error().
Referenced by impl_add_animation(), game_lua_kernel::intf_find_vacant_tile(), and game_lua_kernel::intf_teleport().
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 199 of file lua_unit.cpp.
References utf8::index(), 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().
bool luaW_isunit | ( | lua_State * | L, |
int | index | ||
) |
Test if a Lua value is a unit.
Definition at line 113 of file lua_unit.cpp.
References getunitKey, and utf8::index().
Referenced by internal_get_unit(), game_lua_kernel::intf_erase_unit(), game_lua_kernel::intf_find_vacant_tile(), game_lua_kernel::intf_get_locations(), game_lua_kernel::intf_match_location(), game_lua_kernel::intf_put_recall_unit(), and game_lua_kernel::intf_put_unit().
Pushes a private unit on the stack.
Definition at line 212 of file lua_unit.cpp.
Referenced by game_lua_kernel::apply_effect(), and game_lua_kernel::run_filter().
unit* luaW_tounit | ( | lua_State * | L, |
int | index, | ||
bool | only_on_map | ||
) |
Converts a Lua value to a unit pointer.
Definition at line 142 of file lua_unit.cpp.
References utf8::index(), internal_get_unit(), and LU_OK.
Referenced by ai::cfun_ai_get_suitable_keep(), impl_unit_attacks_len(), impl_unit_status_get(), impl_unit_status_set(), impl_unit_variables_get(), impl_unit_variables_set(), lua_formula_bridge::intf_eval_formula(), game_lua_kernel::intf_find_cost_map(), game_lua_kernel::intf_get_locations(), game_lua_kernel::intf_get_units(), game_lua_kernel::intf_match_location(), game_lua_kernel::intf_match_unit(), luaW_tofaivariant(), and WIDGET_SETTER().
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 152 of file lua_unit.cpp.
References utf8::index(), internal_get_unit(), and LU_OK.
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 162 of file lua_unit.cpp.
References utf8::index(), and internal_get_unit().
Referenced by impl_unit_attacks_get(), and impl_unit_tostring().
|
static |
Definition at line 168 of file lua_unit.cpp.
References utf8::index(), LU_NOT_ON_MAP, LU_NOT_UNIT, LU_NOT_VALID, and luaW_type_error().
Referenced by luaW_checkunit(), luaW_checkunit_ptr(), and luaW_checkunit_ref().
|
static |
Definition at line 40 of file lua_unit.cpp.
Referenced by luaW_isunit(), lua_units::register_metatables(), and lua_unit::setmetatable().
|
static |
|
static |
Definition at line 42 of file lua_unit.cpp.
Referenced by lua_units::register_metatables().
|
static |
Definition at line 41 of file lua_unit.cpp.
Referenced by lua_units::register_metatables().