The Battle for Wesnoth  1.19.7+dev
Classes | Namespaces | Functions
lua_unit.hpp File Reference
#include <cstddef>
#include <string>
#include "scripting/lua_common.hpp"
#include "units/ptr.hpp"
Include dependency graph for lua_unit.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  lua_unit
 Storage for a unit, either owned by the Lua code (ptr != 0), a local variable unit (c_ptr != 0), on a recall list (side != 0), or on the map. More...
 

Namespaces

 lua_units
 

Functions

bool luaW_isunit (lua_State *, int index)
 Test if a Lua value is a unit. More...
 
unitluaW_tounit (lua_State *L, int index, bool only_on_map=false)
 Converts a Lua value to a unit pointer. More...
 
unitluaW_checkunit (lua_State *L, int index, bool only_on_map=false)
 Converts a Lua value to a unit pointer. More...
 
lua_unitluaW_pushlocalunit (lua_State *L, unit &u)
 Pushes a private unit on the stack. 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...
 
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...
 
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...
 
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...
 
template<typename... Args>
lua_unitluaW_pushunit (lua_State *L, Args... args)
 
std::string lua_units::register_metatables (lua_State *L)
 

Function Documentation

◆ luaW_checkunit()

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

◆ 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 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().

◆ 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 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().

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

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

◆ luaW_pushunit()

template<typename... Args>
lua_unit* luaW_pushunit ( lua_State *  L,
Args...  args 
)
inline

◆ luaW_tounit()

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

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

References utf8::index(), 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 162 of file lua_unit.cpp.

References utf8::index(), and internal_get_unit().

Referenced by impl_unit_attacks_get(), and impl_unit_tostring().