#include "config.hpp"
#include "scripting/lua_types.hpp"
#include "variable_info.hpp"
#include "map/location.hpp"
#include <vector>
Go to the source code of this file.
Namespaces | |
lua_common | |
Macros | |
#define | return_tstring_attrib(name, accessor) |
#define | return_cstring_attrib(name, accessor) |
#define | return_string_attrib(name, accessor) return_cstring_attrib(name, (accessor).c_str()) |
#define | return_int_attrib(name, accessor) |
#define | return_float_attrib(name, accessor) |
#define | return_bool_attrib(name, accessor) |
#define | return_cfg_attrib(name, accessor) |
#define | return_cfgref_attrib(name, accessor) |
#define | return_vector_string_attrib(name, accessor) |
#define | modify_tstring_attrib(name, accessor) |
#define | modify_string_attrib(name, accessor) |
#define | modify_int_attrib(name, accessor) |
#define | modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max) |
#define | modify_bool_attrib(name, accessor) |
#define | modify_vector_string_attrib(name, accessor) |
Functions | |
int | lua_common::intf_textdomain (lua_State *L) |
Creates an interface for gettext. More... | |
int | lua_common::intf_tovconfig (lua_State *L) |
Creates a vconfig containing the WML table. More... | |
std::string | lua_common::register_gettext_metatable (lua_State *L) |
Adds the gettext metatable. More... | |
std::string | lua_common::register_tstring_metatable (lua_State *L) |
Adds the tstring metatable. More... | |
std::string | lua_common::register_vconfig_metatable (lua_State *L) |
Adds the vconfig metatable. More... | |
void | luaW_pushvconfig (lua_State *L, vconfig const &cfg) |
Pushes a vconfig on the top of the stack. More... | |
void | luaW_pushtstring (lua_State *L, t_string const &v) |
Pushes a t_string on the top of the stack. More... | |
void | luaW_pushscalar (lua_State *L, config::attribute_value const &v) |
Converts an attribute value into a Lua object pushed at the top of the stack. More... | |
bool | luaW_toscalar (lua_State *L, int index, config::attribute_value &v) |
Converts the value at the top of the stack to an attribute value. More... | |
bool | luaW_hasmetatable (lua_State *L, int index, luatypekey key) |
Returns true if the metatable of the object is the one found in the registry. More... | |
bool | luaW_totstring (lua_State *L, int index, t_string &str) |
Converts a scalar to a translatable string. More... | |
t_string | luaW_checktstring (lua_State *L, int index) |
Converts a scalar to a translatable string. More... | |
void | luaW_filltable (lua_State *L, config const &cfg) |
Converts a config object to a Lua table. More... | |
void | luaW_pushlocation (lua_State *L, map_location const &loc) |
Converts a map location object to a Lua table pushed at the top of the stack. More... | |
bool | luaW_tolocation (lua_State *L, int index, map_location &loc) |
Converts an optional table or pair of integers to a map location object. More... | |
map_location | luaW_checklocation (lua_State *L, int index) |
Converts an optional table or pair of integers to a map location object. More... | |
void | luaW_pushconfig (lua_State *L, config const &cfg) |
Converts a config object to a Lua table pushed at the top of the stack. More... | |
bool | luaW_toconfig (lua_State *L, int index, config &cfg) |
Converts an optional table or vconfig to a config object. More... | |
config | luaW_checkconfig (lua_State *L, int index) |
Converts an optional table or vconfig to a config object. More... | |
bool | luaW_tovconfig (lua_State *L, int index, vconfig &vcfg) |
Gets an optional vconfig from either a table or a userdata. More... | |
vconfig | luaW_checkvconfig (lua_State *L, int index, bool allow_missing=false) |
Gets an optional vconfig from either a table or a userdata. More... | |
bool | luaW_getglobal (lua_State *L, const std::vector< std::string > &path) |
Pushes the value found by following the variadic names (char *), if the value is not nil. More... | |
template<typename... T> | |
bool | luaW_getglobal (lua_State *L, T...path) |
Pushes the value found by following the variadic names (char *), if the value is not nil. More... | |
bool | luaW_toboolean (lua_State *L, int n) |
bool | luaW_pushvariable (lua_State *L, variable_access_const &v) |
bool | luaW_checkvariable (lua_State *L, variable_access_create &v, int n) |
Variables | |
const char * | tstringKey |
#define modify_bool_attrib | ( | name, | |
accessor | |||
) |
Definition at line 252 of file lua_common.hpp.
Referenced by impl_side_set(), and impl_unit_set().
#define modify_int_attrib | ( | name, | |
accessor | |||
) |
Definition at line 237 of file lua_common.hpp.
Referenced by game_lua_kernel::impl_game_config_set(), impl_side_set(), impl_unit_attack_set(), and impl_unit_set().
#define modify_int_attrib_check_range | ( | name, | |
accessor, | |||
allowed_min, | |||
allowed_max | |||
) |
Definition at line 244 of file lua_common.hpp.
#define modify_string_attrib | ( | name, | |
accessor | |||
) |
Definition at line 230 of file lua_common.hpp.
Referenced by impl_side_set(), impl_unit_attack_set(), and impl_unit_set().
#define modify_tstring_attrib | ( | name, | |
accessor | |||
) |
Definition at line 223 of file lua_common.hpp.
Referenced by impl_side_set(), impl_unit_attack_set(), and impl_unit_set().
#define modify_vector_string_attrib | ( | name, | |
accessor | |||
) |
Definition at line 259 of file lua_common.hpp.
Referenced by impl_unit_set().
#define return_bool_attrib | ( | name, | |
accessor | |||
) |
Definition at line 190 of file lua_common.hpp.
Referenced by game_lua_kernel::impl_game_config_get(), impl_race_get(), impl_side_get(), and impl_unit_get().
#define return_cfg_attrib | ( | name, | |
accessor | |||
) |
Definition at line 196 of file lua_common.hpp.
Referenced by impl_side_get(), and impl_unit_get().
#define return_cfgref_attrib | ( | name, | |
accessor | |||
) |
Definition at line 204 of file lua_common.hpp.
Referenced by game_lua_kernel::impl_game_config_get(), impl_race_get(), impl_unit_attack_get(), impl_unit_attack_set(), impl_unit_type_get(), and impl_unit_variables_get().
#define return_cstring_attrib | ( | name, | |
accessor | |||
) |
Definition at line 169 of file lua_common.hpp.
Referenced by impl_side_get().
#define return_float_attrib | ( | name, | |
accessor | |||
) |
Definition at line 184 of file lua_common.hpp.
Referenced by impl_side_get().
#define return_int_attrib | ( | name, | |
accessor | |||
) |
Definition at line 178 of file lua_common.hpp.
Referenced by game_lua_kernel::impl_current_get(), game_lua_kernel::impl_game_config_get(), impl_race_get(), impl_side_get(), impl_unit_attack_get(), impl_unit_get(), and impl_unit_type_get().
#define return_string_attrib | ( | name, | |
accessor | |||
) | return_cstring_attrib(name, (accessor).c_str()) |
Definition at line 175 of file lua_common.hpp.
Referenced by game_lua_kernel::impl_current_get(), game_lua_kernel::impl_game_config_get(), impl_race_get(), impl_side_get(), impl_unit_attack_get(), impl_unit_get(), and impl_unit_type_get().
#define return_tstring_attrib | ( | name, | |
accessor | |||
) |
Definition at line 163 of file lua_common.hpp.
Referenced by impl_race_get(), impl_side_get(), impl_unit_get(), and impl_unit_type_get().
#define return_vector_string_attrib | ( | name, | |
accessor | |||
) |
Definition at line 210 of file lua_common.hpp.
Referenced by impl_unit_get().
Converts an optional table or vconfig to a config object.
Definition at line 749 of file lua_common.cpp.
References luaL_typerror(), and luaW_toconfig().
Referenced by game_lua_kernel::cfun_builtin_effect(), impl_context_backend(), impl_unit_attack_set(), impl_unit_variables_set(), intf_add_modification(), game_lua_kernel::intf_add_sound_source(), game_lua_kernel::intf_add_tile_overlay(), intf_create_unit(), intf_debug(), game_lua_kernel::intf_erase_unit(), game_lua_kernel::intf_find_vacant_tile(), game_lua_kernel::intf_fire_event(), game_lua_kernel::intf_put_recall_unit(), game_lua_kernel::intf_put_unit(), lua_gui2::intf_set_dialog_canvas(), intf_set_music(), lua_check_impl::lua_check(), lua_gui2::show_dialog(), and lua_gui2::show_message_dialog().
map_location luaW_checklocation | ( | lua_State * | L, |
int | index | ||
) |
Converts an optional table or pair of integers to a map location object.
Definition at line 655 of file lua_common.cpp.
References luaL_typerror(), and luaW_tolocation().
Referenced by ai::ai_attack(), ai::ai_move(), ai::ai_stopunit_select(), game_lua_kernel::intf_add_tile_overlay(), game_lua_kernel::intf_find_cost_map(), game_lua_kernel::intf_find_path(), game_lua_kernel::intf_find_reach(), game_lua_kernel::intf_find_vacant_tile(), game_lua_kernel::intf_fire_wml_menu_item(), game_lua_kernel::intf_float_label(), game_lua_kernel::intf_get_terrain(), game_lua_kernel::intf_get_village_owner(), game_lua_kernel::intf_highlight_hex(), game_lua_kernel::intf_match_location(), game_lua_kernel::intf_remove_tile_overlay(), game_lua_kernel::intf_scroll_to_tile(), game_lua_kernel::intf_select_hex(), game_lua_kernel::intf_select_unit(), game_lua_kernel::intf_set_terrain(), game_lua_kernel::intf_set_village_owner(), game_lua_kernel::intf_teleport(), intf_unit_resistance(), and lua_check_impl::lua_check().
Converts a scalar to a translatable string.
Definition at line 562 of file lua_common.cpp.
References luaL_typerror(), and luaW_totstring().
Referenced by game_lua_kernel::intf_float_label(), game_lua_kernel::intf_message(), lua_gui2::intf_set_dialog_value(), game_lua_kernel::intf_set_end_campaign_text(), and lua_check_impl::lua_check().
bool luaW_checkvariable | ( | lua_State * | L, |
variable_access_create & | v, | ||
int | n | ||
) |
Definition at line 845 of file lua_common.cpp.
References variable_info< vit >::as_container(), variable_info< vit >::as_scalar(), config::clear(), variable_info< vit >::get_error_message(), LUA_TBOOLEAN, LUA_TNUMBER, lua_tonumber, lua_tostring, LUA_TSTRING, LUA_TTABLE, LUA_TUSERDATA, lua_type(), lua_typename(), luaL_testudata(), luaL_typerror(), luaW_toboolean(), luaW_toconfig(), tstringKey, and WRN_LUA.
Referenced by impl_unit_variables_set(), game_lua_kernel::intf_set_side_variable(), and game_lua_kernel::intf_set_variable().
Gets an optional vconfig from either a table or a userdata.
allow_missing | true if missing values are allowed; the function then returns an unconstructed vconfig. |
Definition at line 784 of file lua_common.cpp.
References luaL_typerror(), luaW_tovconfig(), vconfig::null(), and vconfig::unconstructed_vconfig().
Referenced by game_lua_kernel::cfun_wml_action(), lua_common::impl_vconfig_ipairs(), lua_common::impl_vconfig_ipairs_iter(), lua_common::impl_vconfig_pairs(), lua_common::impl_vconfig_pairs_iter(), game_lua_kernel::intf_add_event(), game_lua_kernel::intf_add_time_area(), game_lua_kernel::intf_animate_unit(), game_lua_kernel::intf_color_adjust(), game_lua_kernel::intf_end_level(), intf_eval_conditional(), game_lua_kernel::intf_gamestate_inspector(), game_lua_kernel::intf_get_locations(), game_lua_kernel::intf_get_recall_units(), game_lua_kernel::intf_get_sides(), game_lua_kernel::intf_get_units(), game_lua_kernel::intf_get_villages(), game_lua_kernel::intf_heal_unit(), game_lua_kernel::intf_kill(), game_lua_kernel::intf_label(), game_lua_kernel::intf_match_location(), game_lua_kernel::intf_match_side(), game_lua_kernel::intf_match_unit(), game_lua_kernel::intf_modify_ai_wml(), game_lua_kernel::intf_modify_side(), game_lua_kernel::intf_print(), game_lua_kernel::intf_redraw(), game_lua_kernel::intf_replace_schedule(), game_lua_kernel::intf_scroll(), game_lua_kernel::intf_set_menu_item(), game_lua_kernel::intf_shroud_op(), and lua_common::intf_tovconfig().
Converts a config object to a Lua table.
The destination table should be at the top of the stack on entry. It is still at the top on exit.
Definition at line 570 of file lua_common.cpp.
References config::all_children_range(), config::attribute_range(), lua_checkstack(), lua_createtable(), LUA_MINSTACK, lua_newtable, lua_pushstring(), lua_rawseti(), lua_setfield(), luaW_filltable(), and luaW_pushscalar().
Referenced by luaW_filltable(), luaW_pushconfig(), and luaW_pushvariable().
bool luaW_getglobal | ( | lua_State * | L, |
const std::vector< std::string > & | path | ||
) |
Pushes the value found by following the variadic names (char *), if the value is not nil.
Definition at line 792 of file lua_common.cpp.
References lua_isnil, lua_istable, lua_pop, lua_pushglobaltable, lua_pushlstring(), lua_rawget(), and lua_remove().
Referenced by game_lua_kernel::apply_effect(), game_lua_kernel::game_lua_kernel(), ai::impl_ai_aspect_get(), game_lua_kernel::load_game(), luaW_getglobal(), game_lua_kernel::mouse_over_hex_callback(), game_lua_kernel::run_event(), game_lua_kernel::run_filter(), game_lua_kernel::run_wml_action(), game_lua_kernel::run_wml_conditional(), game_lua_kernel::save_game(), and game_lua_kernel::select_hex_callback().
bool luaW_getglobal | ( | lua_State * | L, |
T... | path | ||
) |
Pushes the value found by following the variadic names (char *), if the value is not nil.
Definition at line 151 of file lua_common.hpp.
References luaW_getglobal().
bool luaW_hasmetatable | ( | lua_State * | L, |
int | index, | ||
luatypekey | key | ||
) |
Returns true if the metatable of the object is the one found in the registry.
Definition at line 524 of file lua_common.cpp.
References lua_getmetatable(), lua_pop, lua_pushlightuserdata(), lua_rawequal(), lua_rawget(), and LUA_REGISTRYINDEX.
Referenced by game_lua_kernel::intf_erase_unit(), lua_formula_bridge::intf_eval_formula(), game_lua_kernel::intf_extract_unit(), game_lua_kernel::intf_find_vacant_tile(), game_lua_kernel::intf_match_unit(), game_lua_kernel::intf_put_recall_unit(), game_lua_kernel::intf_put_unit(), luaW_tounit(), and luaW_tounit_ptr().
Converts a config object to a Lua table pushed at the top of the stack.
Definition at line 663 of file lua_common.cpp.
References lua_newtable, and luaW_filltable().
Referenced by game_lua_kernel::apply_effect(), ai::cfun_ai_get_leader_goal(), ai::lua_ai_action_handler::handle(), ai::impl_ai_aspect_get(), impl_context_accessor(), game_lua_kernel::impl_current_get(), impl_race_get(), game_lua_kernel::impl_theme_item(), impl_unit_type_get(), lua_common::impl_vconfig_get(), game_lua_kernel::intf_get_all_vars(), intf_get_era(), game_lua_kernel::intf_get_sound_source(), intf_get_traits(), intf_synchronize_choice(), game_lua_kernel::load_game(), lua_check_impl::lua_push(), mapgen_lua_kernel::run_generator(), lua_kernel_base::run_lua_tag(), application_lua_kernel::thread::run_script(), ai::lua_ai_context::set_arguments(), and ai::lua_ai_context::set_persistent_data().
void luaW_pushlocation | ( | lua_State * | L, |
map_location const & | loc | ||
) |
Converts a map location object to a Lua table pushed at the top of the stack.
Definition at line 593 of file lua_common.cpp.
References lua_createtable(), lua_pushinteger(), lua_rawset(), map_location::x, and map_location::y.
Referenced by ai::cfun_ai_get_targets(), lua_map_location::intf_get_adjacent_tiles(), lua_map_location::intf_get_direction(), lua_map_location::intf_rotate_right_around_center(), game_lua_kernel::intf_select_hex(), lua_map_location::intf_vector_negation(), lua_map_location::intf_vector_sum(), lua_map_location::intf_vector_zero(), lua_check_impl::lua_push(), luaW_pushfaivariant(), ai::push_attack_analysis(), ai::push_move_map(), and ai::push_movements().
void luaW_pushscalar | ( | lua_State * | L, |
config::attribute_value const & | v | ||
) |
Converts an attribute value into a Lua object pushed at the top of the stack.
Definition at line 492 of file lua_common.cpp.
References config::attribute_value::apply_visitor().
Referenced by lua_common::impl_vconfig_get(), lua_common::impl_vconfig_pairs_iter(), luaW_filltable(), and luaW_pushvariable().
Pushes a t_string on the top of the stack.
Definition at line 462 of file lua_common.cpp.
References lua_newuserdata(), luaL_setmetatable(), and tstringKey.
Referenced by lua_common::impl_gettext(), game_lua_kernel::intf_get_terrain_info(), game_lua_kernel::intf_get_time_of_day(), and lua_check_impl::lua_push().
bool luaW_pushvariable | ( | lua_State * | L, |
variable_access_const & | v | ||
) |
Definition at line 816 of file lua_common.cpp.
References variable_info< vit >::as_container(), variable_info< vit >::as_scalar(), variable_info< vit >::exists_as_attribute(), variable_info< vit >::exists_as_container(), variable_info< vit >::get_error_message(), lua_newtable, lua_pushnil(), luaW_filltable(), luaW_pushscalar(), luaW_toboolean(), and WRN_LUA.
Referenced by impl_unit_variables_get(), game_lua_kernel::intf_get_side_variable(), and game_lua_kernel::intf_get_variable().
Pushes a vconfig on the top of the stack.
Definition at line 456 of file lua_common.cpp.
References lua_newuserdata(), luaL_setmetatable(), and vconfigKey.
Referenced by lua_common::impl_vconfig_get(), lua_common::impl_vconfig_ipairs_iter(), lua_common::intf_tovconfig(), game_lua_kernel::run_wml_action(), and game_lua_kernel::run_wml_conditional().
Definition at line 811 of file lua_common.cpp.
References lua_toboolean().
Referenced by ai::ai_move(), ai::call_lua_filter_fcn(), game_lua_kernel::cfun_builtin_effect(), cfun_exec_candidate_action(), ai::impl_ai_get(), impl_unit_status_set(), intf_add_modification(), intf_advance_unit(), game_lua_kernel::intf_allow_end_turn(), game_lua_kernel::intf_allow_undo(), game_lua_kernel::intf_delay(), game_lua_kernel::intf_find_cost_map(), intf_find_path(), game_lua_kernel::intf_find_path(), game_lua_kernel::intf_find_reach(), game_lua_kernel::intf_get_time_of_day(), game_lua_kernel::intf_lock_view(), game_lua_kernel::intf_log(), game_lua_kernel::intf_put_unit(), game_lua_kernel::intf_redraw(), game_lua_kernel::intf_scroll_to_tile(), game_lua_kernel::intf_select_hex(), game_lua_kernel::intf_select_unit(), lua_gui2::intf_set_dialog_active(), lua_gui2::intf_set_dialog_markup(), lua_gui2::intf_set_dialog_value(), lua_gui2::intf_set_dialog_visible(), game_lua_kernel::intf_set_end_campaign_credits(), game_lua_kernel::intf_set_terrain(), game_lua_kernel::intf_set_village_owner(), game_lua_kernel::intf_skip_messages(), game_lua_kernel::intf_teleport(), game_lua_kernel::intf_toggle_fog(), intf_unit_resistance(), ai::lua_ai_load::lua_ai_load(), lua_check_impl::lua_check(), luaW_checkvariable(), luaW_pushvariable(), luaW_toscalar(), game_lua_kernel::run_filter(), game_lua_kernel::run_wml_conditional(), and ai::lua_object< T >::to_type().
Converts an optional table or vconfig to a config object.
index | stack position of the table. |
Definition at line 675 of file lua_common.cpp.
References config::add_child(), i, lua_absindex(), lua_checkstack(), lua_gettop(), lua_isnumber(), lua_isstring(), lua_istable, LUA_MINSTACK, lua_next(), lua_pop, lua_pushnil(), lua_rawgeti(), lua_rawlen(), lua_settop(), LUA_TNIL, LUA_TNONE, lua_tostring, LUA_TTABLE, LUA_TUSERDATA, lua_type(), luaL_testudata(), luaW_toconfig(), luaW_toscalar(), return_misformed, config::attribute_value::str(), and vconfigKey.
Referenced by mapgen_lua_kernel::create_scenario(), ai::lua_ai_context::get_arguments(), ai::lua_ai_context::get_persistent_data(), impl_context_accessor(), intf_modify_ai(), luaW_checkconfig(), luaW_checkvariable(), luaW_toconfig(), luaW_tovconfig(), game_lua_kernel::save_game(), lua_gui2::show_message_dialog(), and ai::lua_object< T >::to_type().
bool luaW_tolocation | ( | lua_State * | L, |
int | index, | ||
map_location & | loc | ||
) |
Converts an optional table or pair of integers to a map location object.
index | stack position of the table or first integer. |
Definition at line 606 of file lua_common.cpp.
References lua_absindex(), lua_checkstack(), lua_getfield(), lua_isnoneornil, lua_isnumber(), lua_istable, lua_isuserdata(), LUA_MINSTACK, lua_pop, lua_rawgeti(), lua_remove(), lua_tonumber, lua_tonumberx(), luaW_tounit(), luaW_tovconfig(), vconfig::unconstructed_vconfig(), map_location::x, and map_location::y.
Referenced by lua_map_location::intf_distance_between(), game_lua_kernel::intf_erase_unit(), game_lua_kernel::intf_fire_event(), lua_map_location::intf_get_adjacent_tiles(), lua_map_location::intf_get_direction(), lua_map_location::intf_get_in_basis_N_NE(), lua_map_location::intf_get_relative_dir(), game_lua_kernel::intf_get_time_of_day(), game_lua_kernel::intf_get_unit(), game_lua_kernel::intf_match_unit(), game_lua_kernel::intf_put_unit(), lua_map_location::intf_rotate_right_around_center(), lua_map_location::intf_tiles_adjacent(), lua_map_location::intf_vector_negation(), lua_map_location::intf_vector_sum(), load_fake_units(), luaW_checklocation(), and luaW_tofaivariant().
bool luaW_toscalar | ( | lua_State * | L, |
int | index, | ||
config::attribute_value & | v | ||
) |
Converts the value at the top of the stack to an attribute value.
Definition at line 497 of file lua_common.cpp.
References LUA_TBOOLEAN, LUA_TNUMBER, lua_tonumber, lua_tostring, LUA_TSTRING, LUA_TUSERDATA, lua_type(), luaL_testudata(), luaW_toboolean(), and tstringKey.
Referenced by luaW_toconfig().
Converts a scalar to a translatable string.
Definition at line 537 of file lua_common.cpp.
References LUA_TBOOLEAN, LUA_TNUMBER, lua_toboolean(), lua_tostring, LUA_TSTRING, LUA_TUSERDATA, lua_type(), luaL_testudata(), and tstringKey.
Referenced by intf_synchronize_choice(), intf_synchronize_choices(), luaW_checktstring(), luaW_tofaivariant(), and lua_gui2::show_message_dialog().
Gets an optional vconfig from either a table or a userdata.
Definition at line 757 of file lua_common.cpp.
References LUA_TNIL, LUA_TNONE, LUA_TTABLE, LUA_TUSERDATA, lua_type(), luaL_testudata(), luaW_toconfig(), and vconfigKey.
Referenced by game_lua_kernel::intf_find_cost_map(), luaW_checkvconfig(), luaW_tofaivariant(), luaW_tolocation(), and ai::lua_object< T >::to_type().
const char* tstringKey |
Definition at line 48 of file lua_common.cpp.
Referenced by lua_common::impl_tstring_concat(), luaW_checkvariable(), luaW_pushtstring(), luaW_toscalar(), luaW_totstring(), lua_common::register_tstring_metatable(), and lua_common::tstring_concat_aux().