The Battle for Wesnoth  1.19.5+dev
Classes | Macros | Typedefs | Functions | Variables
game_lua_kernel.cpp File Reference

Provides a Lua interpreter, to be embedded in WML. More...

#include "scripting/game_lua_kernel.hpp"
#include "actions/attack.hpp"
#include "actions/advancement.hpp"
#include "actions/move.hpp"
#include "actions/vision.hpp"
#include "ai/composite/ai.hpp"
#include "ai/composite/component.hpp"
#include "ai/composite/contexts.hpp"
#include "ai/lua/engine_lua.hpp"
#include "ai/composite/rca.hpp"
#include "ai/composite/stage.hpp"
#include "ai/configuration.hpp"
#include "ai/lua/core.hpp"
#include "ai/manager.hpp"
#include "attack_prediction.hpp"
#include "chat_events.hpp"
#include "config.hpp"
#include "display_chat_manager.hpp"
#include "floating_label.hpp"
#include "formatter.hpp"
#include "game_board.hpp"
#include "game_classification.hpp"
#include "game_config.hpp"
#include "game_config_manager.hpp"
#include "game_data.hpp"
#include "game_display.hpp"
#include "game_errors.hpp"
#include "game_events/conditional_wml.hpp"
#include "game_events/entity_location.hpp"
#include "game_events/handlers.hpp"
#include "game_events/manager_impl.hpp"
#include "game_events/pump.hpp"
#include "preferences/preferences.hpp"
#include "log.hpp"
#include "map/map.hpp"
#include "map/label.hpp"
#include "map/location.hpp"
#include "mouse_events.hpp"
#include "mp_game_settings.hpp"
#include "overlay.hpp"
#include "pathfind/pathfind.hpp"
#include "pathfind/teleport.hpp"
#include "play_controller.hpp"
#include "recall_list_manager.hpp"
#include "replay.hpp"
#include "reports.hpp"
#include "resources.hpp"
#include "scripting/lua_attributes.hpp"
#include "scripting/lua_audio.hpp"
#include "scripting/lua_unit.hpp"
#include "scripting/lua_unit_attacks.hpp"
#include "scripting/lua_common.hpp"
#include "scripting/lua_cpp_function.hpp"
#include "scripting/lua_gui2.hpp"
#include "scripting/lua_pathfind_cost_calculator.hpp"
#include "scripting/lua_race.hpp"
#include "scripting/lua_team.hpp"
#include "scripting/lua_terrainmap.hpp"
#include "scripting/lua_unit_type.hpp"
#include "scripting/push_check.hpp"
#include "synced_commands.hpp"
#include "color.hpp"
#include "side_filter.hpp"
#include "sound.hpp"
#include "synced_context.hpp"
#include "synced_user_choice.hpp"
#include "team.hpp"
#include "terrain/terrain.hpp"
#include "terrain/filter.hpp"
#include "terrain/translation.hpp"
#include "time_of_day.hpp"
#include "tod_manager.hpp"
#include "tstring.hpp"
#include "units/unit.hpp"
#include "units/animation_component.hpp"
#include "units/udisplay.hpp"
#include "units/filter.hpp"
#include "units/map.hpp"
#include "units/ptr.hpp"
#include "units/types.hpp"
#include "utils/scope_exit.hpp"
#include "variable.hpp"
#include "variable_info.hpp"
#include "video.hpp"
#include "whiteboard/manager.hpp"
#include "deprecation.hpp"
#include <functional>
#include <array>
#include <cassert>
#include <cstring>
#include <iterator>
#include <map>
#include <new>
#include <set>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <SDL2/SDL_timer.h>
Include dependency graph for game_lua_kernel.cpp:

Go to the source code of this file.

Classes

struct  map_locker
 
struct  schedule_tag
 
struct  lua_object_traits< schedule_tag >
 
struct  game_config_glk_tag
 
struct  scenario_tag
 
struct  lua_object_traits< scenario_tag >
 
struct  current_tag
 
struct  lua_object_traits< current_tag >
 
struct  lua_event_filter
 
struct  callbacks_tag
 
struct  lua_object_traits< callbacks_tag >
 

Macros

#define DBG_LUA   LOG_STREAM(debug, log_scripting_lua)
 
#define LOG_LUA   LOG_STREAM(info, log_scripting_lua)
 
#define WRN_LUA   LOG_STREAM(warn, log_scripting_lua)
 
#define ERR_LUA   LOG_STREAM(err, log_scripting_lua)
 
#define ERR_WML   LOG_STREAM(err, log_wml)
 
#define SCHEDULE_GETTER(name, type)   LATTR_GETTER(name, type, schedule_tag, sched)
 
#define SCHEDULE_SETTER(name, type)   LATTR_SETTER(name, type, schedule_tag, sched)
 
#define SCHEDULE_VALID(name)   LATTR_VALID(name, schedule_tag, sched)
 
#define GAME_CONFIG_SIMPLE_SETTER(name)
 
#define SCENARIO_GETTER(name, type)   LATTR_GETTER(name, type, scenario_tag, k)
 
#define SCENARIO_SETTER(name, type)   LATTR_SETTER(name, type, scenario_tag, k)
 
#define SCENARIO_VALID(name)   LATTR_VALID(name, scenario_tag, k)
 
#define CURRENT_GETTER(name, type)   LATTR_GETTER(name, type, current_tag, k)
 
#define READ_ONE_FILTER(key, tag)
 
#define CALLBACK_GETTER(name, type)   LATTR_GETTER(name, lua_index_raw, callbacks_tag, ) { lua_pushcfunction(L, &impl_null_callback<type>); return lua_index_raw(L); }
 

Typedefs

typedef int(game_lua_kernel::* member_callback) (lua_State *)
 
typedef int(game_lua_kernel::* member_callback2) (lua_State *, bool)
 
using wml_conditional_handler = bool(*)(const vconfig &)
 

Functions

template<member_callback method>
int dispatch (lua_State *L)
 
template<member_callback2 method, bool b>
int dispatch2 (lua_State *L)
 
static int intf_get_viewing_side (lua_State *L)
 Gets currently viewing side. More...
 
static int intf_handle_user_interact (lua_State *)
 
static int impl_animator_collect (lua_State *L)
 
static int impl_add_animation (lua_State *L)
 
static int impl_clear_animation (lua_State *L)
 
static int impl_animator_get (lua_State *L)
 
static void luaW_push_tod (lua_State *L, const time_of_day &tod)
 
static int luaW_check_schedule (lua_State *L, int idx)
 
static int intf_get_resource (lua_State *L)
 Gets a table for an resource tag. More...
 
static int intf_get_era (lua_State *L)
 Gets a table for an era tag. More...
 
luaW_RegistrygameConfigReg ()
 
static int impl_end_level_data_get (lua_State *L)
 
static int impl_end_level_data_collect (lua_State *L)
 
static int impl_mp_settings_get (lua_State *L)
 
static int impl_mp_settings_len (lua_State *L)
 
static int intf_eval_conditional (lua_State *L)
 Evaluates a boolean WML conditional. More...
 
template<typename T >
static int load_fake_units (lua_State *L, int arg, T &fake_units)
 
static int * luaW_check_floating_label (lua_State *L, int idx)
 
static int impl_floating_label_getmethod (lua_State *L)
 
static int intf_create_unit (lua_State *L)
 Creates a unit from its WML description. More...
 
static int intf_copy_unit (lua_State *L)
 Copies a unit. More...
 
static int intf_unit_resistance (lua_State *L)
 Returns unit resistance against a given attack type. More...
 
static int intf_unit_movement_cost (lua_State *L)
 Returns unit movement cost on a given terrain. More...
 
static int intf_unit_vision_cost (lua_State *L)
 Returns unit vision cost on a given terrain. More...
 
static int intf_unit_jamming_cost (lua_State *L)
 Returns unit jamming cost on a given terrain. More...
 
static int intf_unit_defense (lua_State *L)
 Returns unit defense on a given terrain. More...
 
static int intf_transform_unit (lua_State *L)
 Changes a unit to the given unit type. More...
 
static void luaW_pushsimdata (lua_State *L, const combatant &cmb)
 Puts a table at the top of the stack with some combat result. More...
 
static void luaW_pushsimweapon (lua_State *L, const battle_context_unit_stats &bcustats)
 Puts a table at the top of the stack with information about the combatants' weapons. More...
 
static int intf_synchronize_choice (lua_State *L)
 Ensures a value is synchronized among all the clients. More...
 
static int intf_synchronize_choices (lua_State *L)
 Ensures a value is synchronized among all the clients. More...
 
static int intf_do_unsynced (lua_State *L)
 Calls a function in an unsynced context (this specially means that all random calls used by that function will be unsynced). More...
 
static int intf_modify_ai (lua_State *L, const char *action)
 
static int intf_switch_ai (lua_State *L)
 
static int intf_append_ai (lua_State *L)
 
static int intf_add_modification (lua_State *L)
 Adds a modification to a unit. More...
 
static int intf_remove_modifications (lua_State *L)
 Removes modifications from a unit. More...
 
static int intf_advance_unit (lua_State *L)
 Advances a unit if the unit has enough xp. More...
 
static int intf_add_known_unit (lua_State *L)
 Adds a new known unit type to the help system. More...
 
static std::string read_event_name (lua_State *L, int idx)
 
static int intf_modify_ai_old (lua_State *L)
 Lua frontend to the modify_ai functionality. More...
 
static int cfun_exec_candidate_action (lua_State *L)
 
static int cfun_exec_stage (lua_State *L)
 
static void push_component (lua_State *L, ai::component *c, const std::string &ct="")
 
static int intf_debug_ai (lua_State *L)
 Debug access to the ai tables. More...
 
static int intf_invoke_synced_command (lua_State *L)
 
template<typename Ret >
static int impl_null_callback (lua_State *L)
 
static int impl_game_events_dir (lua_State *L)
 
static int impl_game_events_get (lua_State *L)
 
template<typename Ret = void>
static bool impl_get_callback (lua_State *L, const std::string &name)
 
static bool is_handled_file_tag (std::string_view s)
 These are the child tags of [scenario] (and the like) that are handled elsewhere (in the C++ code). More...
 
static int cfun_wml_condition (lua_State *L)
 Executes its upvalue as a wml condition and returns the result. More...
 
static int intf_run_event_wml (lua_State *L)
 

Variables

static lg::log_domain log_scripting_lua ("scripting/lua")
 
static lg::log_domain log_wml ("wml")
 
static const char animatorKey [] = "unit animator"
 
luaW_Registry scheduleReg {"schedule"}
 
static auto & dummy = gameConfigReg()
 
luaW_Registry scenarioReg {"scenario"}
 
luaW_Registry currentReg {"current"}
 
const char * labelKey = "floating label"
 
luaW_Registry callbacksReg {"game_events"}
 

Detailed Description

Provides a Lua interpreter, to be embedded in WML.

Note
Naming conventions:
  • intf_ functions are exported in the wesnoth domain,
  • impl_ functions are hidden inside metatables,
  • cfun_ functions are closures,
  • luaW_ functions are helpers in Lua style.

Definition in file game_lua_kernel.cpp.

Macro Definition Documentation

◆ CALLBACK_GETTER

#define CALLBACK_GETTER (   name,
  type 
)    LATTR_GETTER(name, lua_index_raw, callbacks_tag, ) { lua_pushcfunction(L, &impl_null_callback<type>); return lua_index_raw(L); }

Definition at line 5132 of file game_lua_kernel.cpp.

◆ CURRENT_GETTER

#define CURRENT_GETTER (   name,
  type 
)    LATTR_GETTER(name, type, current_tag, k)

Definition at line 1846 of file game_lua_kernel.cpp.

◆ DBG_LUA

#define DBG_LUA   LOG_STREAM(debug, log_scripting_lua)

Definition at line 135 of file game_lua_kernel.cpp.

◆ ERR_LUA

#define ERR_LUA   LOG_STREAM(err, log_scripting_lua)

Definition at line 138 of file game_lua_kernel.cpp.

◆ ERR_WML

#define ERR_WML   LOG_STREAM(err, log_wml)

Definition at line 141 of file game_lua_kernel.cpp.

◆ GAME_CONFIG_SIMPLE_SETTER

#define GAME_CONFIG_SIMPLE_SETTER (   name)
Value:
GAME_CONFIG_SETTER(#name, decltype(game_config::name), game_lua_kernel) { \
(void) k; \
game_config::name = value; \
}
#define GAME_CONFIG_SETTER(name, type, kernel_type)

Definition at line 1354 of file game_lua_kernel.cpp.

◆ LOG_LUA

#define LOG_LUA   LOG_STREAM(info, log_scripting_lua)

Definition at line 136 of file game_lua_kernel.cpp.

◆ READ_ONE_FILTER

#define READ_ONE_FILTER (   key,
  tag 
)
Value:
do { \
if(luaW_tableget(L, filterIdx, key)) { \
if(lua_isstring(L, -1)) { \
filters.add_child("insert_tag", config{ \
"name", tag, \
"variable", luaL_checkstring(L, -1) \
}); \
} else { \
filters.add_child(tag, luaW_checkconfig(L, -1)); \
} \
} \
} while(false);
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
Definition: lua_common.cpp:927
bool luaW_tableget(lua_State *L, int index, const char *key)
std::string tag(const std::string &tag_name, Args &&... contents)
Returns the contents enclosed inside <tag_name> and </tag_name>
Definition: markup.hpp:35

◆ SCENARIO_GETTER

#define SCENARIO_GETTER (   name,
  type 
)    LATTR_GETTER(name, type, scenario_tag, k)

Definition at line 1603 of file game_lua_kernel.cpp.

◆ SCENARIO_SETTER

#define SCENARIO_SETTER (   name,
  type 
)    LATTR_SETTER(name, type, scenario_tag, k)

Definition at line 1604 of file game_lua_kernel.cpp.

◆ SCENARIO_VALID

#define SCENARIO_VALID (   name)    LATTR_VALID(name, scenario_tag, k)

Definition at line 1605 of file game_lua_kernel.cpp.

◆ SCHEDULE_GETTER

#define SCHEDULE_GETTER (   name,
  type 
)    LATTR_GETTER(name, type, schedule_tag, sched)

Definition at line 935 of file game_lua_kernel.cpp.

◆ SCHEDULE_SETTER

#define SCHEDULE_SETTER (   name,
  type 
)    LATTR_SETTER(name, type, schedule_tag, sched)

Definition at line 936 of file game_lua_kernel.cpp.

◆ SCHEDULE_VALID

#define SCHEDULE_VALID (   name)    LATTR_VALID(name, schedule_tag, sched)

Definition at line 937 of file game_lua_kernel.cpp.

◆ WRN_LUA

#define WRN_LUA   LOG_STREAM(warn, log_scripting_lua)

Definition at line 137 of file game_lua_kernel.cpp.

Typedef Documentation

◆ member_callback

typedef int(game_lua_kernel::* member_callback) (lua_State *)

Definition at line 147 of file game_lua_kernel.cpp.

◆ member_callback2

typedef int(game_lua_kernel::* member_callback2) (lua_State *, bool)

Definition at line 155 of file game_lua_kernel.cpp.

◆ wml_conditional_handler

using wml_conditional_handler = bool(*)(const vconfig&)

Definition at line 5928 of file game_lua_kernel.cpp.

Function Documentation

◆ cfun_exec_candidate_action()

static int cfun_exec_candidate_action ( lua_State *  L)
static

◆ cfun_exec_stage()

static int cfun_exec_stage ( lua_State *  L)
static

Definition at line 4579 of file game_lua_kernel.cpp.

References ai::stage::play_stage().

Referenced by push_component().

◆ cfun_wml_condition()

static int cfun_wml_condition ( lua_State *  L)
static

Executes its upvalue as a wml condition and returns the result.

Definition at line 5933 of file game_lua_kernel.cpp.

References h, and luaW_checkvconfig().

Referenced by game_lua_kernel::set_wml_condition().

◆ dispatch()

template<member_callback method>
int dispatch ( lua_State *  L)

Definition at line 150 of file game_lua_kernel.cpp.

◆ dispatch2()

template<member_callback2 method, bool b>
int dispatch2 ( lua_State *  L)

Definition at line 158 of file game_lua_kernel.cpp.

References b.

◆ gameConfigReg()

luaW_Registry & gameConfigReg ( )

◆ impl_add_animation()

static int impl_add_animation ( lua_State *  L)
static

◆ impl_animator_collect()

static int impl_animator_collect ( lua_State *  L)
static

Definition at line 265 of file game_lua_kernel.cpp.

References animatorKey.

Referenced by game_lua_kernel::intf_create_animator().

◆ impl_animator_get()

static int impl_animator_get ( lua_State *  L)
static

Definition at line 394 of file game_lua_kernel.cpp.

References luaW_getmetafield().

Referenced by game_lua_kernel::intf_create_animator().

◆ impl_clear_animation()

static int impl_clear_animation ( lua_State *  L)
static

Definition at line 387 of file game_lua_kernel.cpp.

References animatorKey, and unit_animator::clear().

Referenced by game_lua_kernel::intf_create_animator().

◆ impl_end_level_data_collect()

static int impl_end_level_data_collect ( lua_State *  L)
static

Definition at line 1459 of file game_lua_kernel.cpp.

References data.

◆ impl_end_level_data_get()

static int impl_end_level_data_get ( lua_State *  L)
static

◆ impl_floating_label_getmethod()

static int impl_floating_label_getmethod ( lua_State *  L)
static

◆ impl_game_events_dir()

static int impl_game_events_dir ( lua_State *  L)
static

Definition at line 5158 of file game_lua_kernel.cpp.

References callbacksReg, and luaW_Registry::dir().

Referenced by game_lua_kernel::game_lua_kernel().

◆ impl_game_events_get()

static int impl_game_events_get ( lua_State *  L)
static

Definition at line 5162 of file game_lua_kernel.cpp.

References callbacksReg, and luaW_Registry::get().

Referenced by game_lua_kernel::game_lua_kernel().

◆ impl_get_callback()

template<typename Ret = void>
static bool impl_get_callback ( lua_State *  L,
const std::string &  name 
)
static

◆ impl_mp_settings_get()

static int impl_mp_settings_get ( lua_State *  L)
static

◆ impl_mp_settings_len()

static int impl_mp_settings_len ( lua_State *  L)
static

Definition at line 1586 of file game_lua_kernel.cpp.

References p.

◆ impl_null_callback()

template<typename Ret >
static int impl_null_callback ( lua_State *  L)
static

Definition at line 5136 of file game_lua_kernel.cpp.

References lua_push().

◆ intf_add_known_unit()

static int intf_add_known_unit ( lua_State *  L)
static

Adds a new known unit type to the help system.

  • Arg 1: string.

Definition at line 4080 of file game_lua_kernel.cpp.

References prefs::encountered_units(), unit_type_data::find(), prefs::get(), and unit_types.

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_add_modification()

static int intf_add_modification ( lua_State *  L)
static

Adds a modification to a unit.

  • Arg 1: unit.
  • Arg 2: string.
  • Arg 3: WML table.
  • Arg 4: (optional) Whether to add to [modifications] - default true

Definition at line 3995 of file game_lua_kernel.cpp.

References unit::add_modification(), deprecated_message(), luaW_checkconfig(), luaW_checkunit(), luaW_toboolean(), and PREEMPTIVE.

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_advance_unit()

static int intf_advance_unit ( lua_State *  L)
static

Advances a unit if the unit has enough xp.

  • Arg 1: unit.
  • Arg 2: optional boolean whether to animate the advancement.
  • Arg 3: optional boolean whether to fire advancement events.

Definition at line 4060 of file game_lua_kernel.cpp.

References advance_unit_at(), advance_unit_params::animate(), advance_unit_params::fire_events(), unit::get_location(), luaW_checkunit(), and luaW_toboolean().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_append_ai()

static int intf_append_ai ( lua_State *  L)
static

◆ intf_copy_unit()

static int intf_copy_unit ( lua_State *  L)
static

Copies a unit.

  • Arg 1: unit userdata.
  • Ret 1: unit userdata.

Definition at line 2984 of file game_lua_kernel.cpp.

References unit::clone(), luaW_checkunit(), and luaW_pushunit().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_create_unit()

static int intf_create_unit ( lua_State *  L)
static

Creates a unit from its WML description.

  • Arg 1: WML table.
  • Ret 1: unit userdata.

Definition at line 2970 of file game_lua_kernel.cpp.

References unit::create(), luaW_checkconfig(), and luaW_pushunit().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_debug_ai()

static int intf_debug_ai ( lua_State *  L)
static

◆ intf_do_unsynced()

static int intf_do_unsynced ( lua_State *  L)
static

Calls a function in an unsynced context (this specially means that all random calls used by that function will be unsynced).

This is usually used together with an unsynced if like 'if controller != network'

  • Arg 1: function that will be called during the unsynced context.

Definition at line 3755 of file game_lua_kernel.cpp.

References luaW_pcall().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_eval_conditional()

static int intf_eval_conditional ( lua_State *  L)
static

Evaluates a boolean WML conditional.

  • Arg 1: WML table.
  • Ret 1: boolean.

Definition at line 2004 of file game_lua_kernel.cpp.

References b, game_events::conditional_passed(), and luaW_checkvconfig().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_get_era()

static int intf_get_era ( lua_State *  L)
static

Gets a table for an era tag.

  • Arg 1: userdata (ignored).
  • Arg 2: string containing id of the desired era
  • Ret 1: config for the era

Definition at line 1331 of file game_lua_kernel.cpp.

References game_config_manager::get(), and luaW_pushconfig().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_get_resource()

static int intf_get_resource ( lua_State *  L)
static

Gets a table for an resource tag.

  • Arg 1: userdata (ignored).
  • Arg 2: string containing id of the desired resource
  • Ret 1: config for the era

Definition at line 1313 of file game_lua_kernel.cpp.

References game_config_manager::get(), and luaW_pushconfig().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_get_viewing_side()

static int intf_get_viewing_side ( lua_State *  L)
static

Gets currently viewing side.

  • Ret 1: integer specifying the currently viewing side
  • Ret 2: Bool whether the vision is not limited to that team, this can for example be true during replays.

Definition at line 245 of file game_lua_kernel.cpp.

References display::get_singleton().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_handle_user_interact()

static int intf_handle_user_interact ( lua_State *  )
static

◆ intf_invoke_synced_command()

static int intf_invoke_synced_command ( lua_State *  L)
static

◆ intf_modify_ai()

static int intf_modify_ai ( lua_State *  L,
const char *  action 
)
static

◆ intf_modify_ai_old()

static int intf_modify_ai_old ( lua_State *  L)
static

Lua frontend to the modify_ai functionality.

  • Arg 1: config.

Definition at line 4553 of file game_lua_kernel.cpp.

References ai::manager::get_singleton(), luaW_toconfig(), and ai::manager::modify_active_ai_for_side().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_remove_modifications()

static int intf_remove_modifications ( lua_State *  L)
static

Removes modifications from a unit.

  • Arg 1: unit
  • Arg 2: table (filter as [filter_wml])
  • Arg 3: type of modification (default "object")

Definition at line 4026 of file game_lua_kernel.cpp.

References config::all_children_count(), config::attribute_count(), config::attribute_range(), config::child_range(), unit::expire_modifications(), unit::get_modifications(), luaW_checkconfig(), luaW_checkunit(), and markup::tag().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_run_event_wml()

static int intf_run_event_wml ( lua_State *  L)
static

Definition at line 6013 of file game_lua_kernel.cpp.

References luaW_getglobal().

Referenced by game_lua_kernel::save_wml_event().

◆ intf_switch_ai()

static int intf_switch_ai ( lua_State *  L)
static

◆ intf_synchronize_choice()

static int intf_synchronize_choice ( lua_State *  L)
static

Ensures a value is synchronized among all the clients.

  • Arg 1: optional string specifying the type id of the choice.
  • Arg 2: function to compute the value, called if the client is the master.
  • Arg 3: optional function, called instead of the first function if the user is not human.
  • Arg 4: optional integer specifying, on which side the function should be evaluated.
  • Ret 1: WML table returned by the function.

Definition at line 3687 of file game_lua_kernel.cpp.

References _(), mp_sync::get_user_choice(), luaW_pushconfig(), and luaW_totstring().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_synchronize_choices()

static int intf_synchronize_choices ( lua_State *  L)
static

Ensures a value is synchronized among all the clients.

  • Arg 1: optional string the id of this type of user input, may only contain characters a-z and '_'
  • Arg 2: function to compute the value, called if the client is the master.
  • Arg 3: an optional function to compute the value, if the side was null/empty controlled.
  • Arg 4: an array of integers specifying, on which side the function should be evaluated.
  • Ret 1: a map int -> WML tabls.

Definition at line 3722 of file game_lua_kernel.cpp.

References _(), mp_sync::get_user_choice_multiple_sides(), lua_push(), and luaW_totstring().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_transform_unit()

static int intf_transform_unit ( lua_State *  L)
static

Changes a unit to the given unit type.

  • Arg 1: unit userdata.
  • Arg 2: unit type name
  • Arg 3: (optional) unit variation name

Definition at line 3123 of file game_lua_kernel.cpp.

References unit::advance_to(), unit_type_data::find(), unit_type::get_variation(), unit_type::has_variation(), luaW_checkunit(), and unit_types.

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_unit_defense()

static int intf_unit_defense ( lua_State *  L)
static

Returns unit defense on a given terrain.

  • Arg 1: unit userdata.
  • Arg 2: string containing the terrain type.
  • Ret 1: integer.

Definition at line 3088 of file game_lua_kernel.cpp.

References unit::defense_modifier(), resources::gameboard, luaW_checkunit(), luaW_tolocation(), luaW_type_error(), t_translation::read_terrain_code(), and t.

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_unit_jamming_cost()

static int intf_unit_jamming_cost ( lua_State *  L)
static

Returns unit jamming cost on a given terrain.

  • Arg 1: unit userdata.
  • Arg 2: string containing the terrain type.
  • Ret 1: integer.

Definition at line 3067 of file game_lua_kernel.cpp.

References resources::gameboard, unit::jamming_cost(), luaW_checkunit(), luaW_tolocation(), luaW_type_error(), t_translation::read_terrain_code(), and t.

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_unit_movement_cost()

static int intf_unit_movement_cost ( lua_State *  L)
static

Returns unit movement cost on a given terrain.

  • Arg 1: unit userdata.
  • Arg 2: string containing the terrain type.
  • Ret 1: integer.

Definition at line 3025 of file game_lua_kernel.cpp.

References resources::gameboard, luaW_checkunit(), luaW_tolocation(), luaW_type_error(), unit::movement_cost(), t_translation::read_terrain_code(), and t.

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_unit_resistance()

static int intf_unit_resistance ( lua_State *  L)
static

Returns unit resistance against a given attack type.

  • Arg 1: unit userdata.
  • Arg 2: string containing the attack type.
  • Arg 3: boolean indicating if attacker.
  • Arg 4: optional location.
  • Ret 1: integer.

Definition at line 2999 of file game_lua_kernel.cpp.

References unit::get_location(), luaW_checklocation(), luaW_checkunit(), luaW_toboolean(), and unit::resistance_against().

Referenced by game_lua_kernel::game_lua_kernel().

◆ intf_unit_vision_cost()

static int intf_unit_vision_cost ( lua_State *  L)
static

Returns unit vision cost on a given terrain.

  • Arg 1: unit userdata.
  • Arg 2: string containing the terrain type.
  • Ret 1: integer.

Definition at line 3046 of file game_lua_kernel.cpp.

References resources::gameboard, luaW_checkunit(), luaW_tolocation(), luaW_type_error(), t_translation::read_terrain_code(), t, and unit::vision_cost().

Referenced by game_lua_kernel::game_lua_kernel().

◆ is_handled_file_tag()

static bool is_handled_file_tag ( std::string_view  s)
static

These are the child tags of [scenario] (and the like) that are handled elsewhere (in the C++ code).

Any child tags not in this list will be passed to Lua's on_load event.

Definition at line 5716 of file game_lua_kernel.cpp.

References s.

Referenced by game_lua_kernel::load_game(), and game_lua_kernel::save_game().

◆ load_fake_units()

template<typename T >
static int load_fake_units ( lua_State *  L,
int  arg,
T &  fake_units 
)
static

Definition at line 2266 of file game_lua_kernel.cpp.

References resources::fake_units, i, luaW_tolocation(), and src.

Referenced by game_lua_kernel::intf_find_cost_map().

◆ luaW_check_floating_label()

static int* luaW_check_floating_label ( lua_State *  L,
int  idx 
)
static

◆ luaW_check_schedule()

static int luaW_check_schedule ( lua_State *  L,
int  idx 
)
static

◆ luaW_push_tod()

static void luaW_push_tod ( lua_State *  L,
const time_of_day tod 
)
static

◆ luaW_pushsimdata()

static void luaW_pushsimdata ( lua_State *  L,
const combatant cmb 
)
static

Puts a table at the top of the stack with some combat result.

Definition at line 3142 of file game_lua_kernel.cpp.

References combatant::average_hp(), combatant::hp_dist, i, n, combatant::poisoned, combatant::slowed, and combatant::untouched.

Referenced by game_lua_kernel::intf_simulate_combat().

◆ luaW_pushsimweapon()

static void luaW_pushsimweapon ( lua_State *  L,
const battle_context_unit_stats bcustats 
)
static

◆ push_component()

static void push_component ( lua_State *  L,
ai::component c,
const std::string &  ct = "" 
)
static

Definition at line 4588 of file game_lua_kernel.cpp.

References c, cfun_exec_candidate_action(), cfun_exec_stage(), i, and t.

Referenced by intf_debug_ai().

◆ read_event_name()

static std::string read_event_name ( lua_State *  L,
int  idx 
)
static

Variable Documentation

◆ animatorKey

const char animatorKey[] = "unit animator"
static

◆ callbacksReg

luaW_Registry callbacksReg {"game_events"}

Definition at line 5133 of file game_lua_kernel.cpp.

Referenced by impl_game_events_dir(), and impl_game_events_get().

◆ currentReg

luaW_Registry currentReg {"current"}

◆ dummy

auto& dummy = gameConfigReg()
static

◆ labelKey

const char* labelKey = "floating label"

◆ log_scripting_lua

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

◆ log_wml

lg::log_domain log_wml("wml") ( "wml"  )
static

◆ scenarioReg

luaW_Registry scenarioReg {"scenario"}

◆ scheduleReg

luaW_Registry scheduleReg {"schedule"}