#include <lua_kernel_base.hpp>
Classes | |
struct | command_log |
Log implementation. More... | |
Public Types | |
using | external_log_type = std::function< void(const std::string &)> |
typedef std::function< void(char const *, char const *)> | error_handler |
Public Member Functions | |
lua_kernel_base () | |
virtual | ~lua_kernel_base () |
void | run_lua_tag (const config &cfg) |
Runs a [lua] tag. More... | |
void | run (char const *prog, const std::string &name, int nArgs=0) |
Runs a plain script. More... | |
void | throwing_run (char const *prog, const std::string &name, int nArgs, bool in_interpreter=false) |
Runs a plain script, but reports errors by throwing lua_error. More... | |
void | interactive_run (char const *prog) |
Tests if a program resolves to an expression, and pretty prints it if it is, otherwise it runs it normally. More... | |
void | load_package () |
Loads the package library into lua environment. More... | |
void | load_core () |
Loads the "core" library into the Lua environment. More... | |
std::vector< std::string > | get_global_var_names () |
Get tab completion strings. More... | |
std::vector< std::string > | get_attribute_names (const std::string &var_path) |
Gets all attribute names of an extended variable name. More... | |
virtual std::string | my_name () |
User-visible name of the lua kernel that they are talking to. More... | |
const std::stringstream & | get_log () |
Access / manipulate logging of lua kernel activities. More... | |
void | add_log (const char *str) |
void | clear_log () |
void | set_external_log (external_log_type lg) |
virtual void | log_error (char const *msg, char const *context="Lua error") |
Error reporting mechanisms, used by virtual methods protected_call and load_string. More... | |
virtual void | throw_exception (char const *msg, char const *context="Lua error") |
virtual uint32_t | get_random_seed () |
lua_State * | get_state () |
void | add_widget_definition (const std::string &type, const std::string &id) |
void | add_log_to_console (const std::string &msg) |
int | intf_show_lua_console (lua_State *L) |
Static Public Member Functions | |
template<typename T > | |
static T & | get_lua_kernel (lua_State *L) |
Protected Member Functions | |
int | intf_print (lua_State *L) |
Replacement print function – instead of printing to std::cout, print to the command log. More... | |
bool | protected_call (int nArgs, int nRets, const error_handler &) |
bool | load_string (char const *prog, const std::string &name, const error_handler &) |
virtual bool | protected_call (int nArgs, int nRets) |
virtual bool | load_string (char const *prog, const std::string &name) |
int | intf_dofile (lua_State *L) |
Loads and executes a Lua file. More... | |
int | intf_require (lua_State *L) |
Loads and executes a Lua file, if there is no corresponding entry in wesnoth.package. More... | |
int | intf_kernel_type (lua_State *L) |
int | impl_game_config_get (lua_State *L) |
Gets some game_config data (__index metamethod). More... | |
int | impl_game_config_set (lua_State *L) |
Sets some game_config data (__newindex metamethod). More... | |
int | impl_game_config_dir (lua_State *L) |
Gets a list of game_config data (__dir metamethod). More... | |
Static Protected Member Functions | |
static bool | protected_call (lua_State *L, int nArgs, int nRets, const error_handler &) |
Protected Attributes | |
lua_State * | mState |
command_log | cmd_log_ |
Static Private Member Functions | |
static lua_kernel_base *& | get_lua_kernel_base_ptr (lua_State *L) |
Private Attributes | |
std::vector< std::tuple< std::string, std::string > > | registered_widget_definitions_ |
Definition at line 27 of file lua_kernel_base.hpp.
typedef std::function<void(char const*, char const*)> lua_kernel_base::error_handler |
Definition at line 70 of file lua_kernel_base.hpp.
using lua_kernel_base::external_log_type = std::function<void(const std::string &)> |
Definition at line 63 of file lua_kernel_base.hpp.
lua_kernel_base::lua_kernel_base | ( | ) |
Definition at line 741 of file lua_kernel_base.cpp.
References cmd_log_, Gen, randomness::generator, get_lua_kernel_base_ptr(), impl_name_generator_call(), impl_name_generator_collect(), impl_warn(), Interp, lua_formula_bridge::intf_compile_formula(), intf_current_version(), intf_deprecated_message(), lua_map_location::intf_distance_between(), lua_formula_bridge::intf_eval_formula(), lua_map_location::intf_get_adjacent_tiles(), lua_map_location::intf_get_direction(), lua_map_location::intf_get_from_cubic(), lua_map_location::intf_get_in_cubic(), intf_get_language(), lua_map_location::intf_get_relative_dir(), lua_map_location::intf_get_tile_ring(), lua_map_location::intf_get_tiles_in_radius(), intf_load(), intf_log(), intf_make_shroud_bitmap(), intf_make_version(), intf_ms_since_init(), intf_name_generator(), intf_named_tuple(), intf_object_dir(), intf_parse_shroud_bitmap(), intf_pcall(), intf_require(), lua_map_location::intf_rotate_right_around_center(), lua_common::intf_textdomain(), lua_map_location::intf_tiles_adjacent(), lua_map_location::intf_vector_diff(), lua_map_location::intf_vector_negation(), lua_map_location::intf_vector_sum(), lua_rng::load_tables(), log_error(), luaW_getglobal(), lua_fileops::luaW_open(), lua_gui2::luaW_open(), lua_mathx::luaW_open(), lua_stringx::luaW_open(), lua_wml::luaW_open(), mState, my_name(), protected_call(), push_error_handler(), lua_common::register_gettext_metatable(), lua_cpp::register_metatable(), lua_widget::register_metatable(), lua_formula_bridge::register_metatables(), lua_colors::register_metatables(), and lua_common::register_tstring_metatable().
|
virtual |
Definition at line 1000 of file lua_kernel_base.cpp.
References mState, registered_widget_definitions_, and gui2::remove_single_widget_definition().
|
inline |
Definition at line 60 of file lua_kernel_base.hpp.
References cmd_log_.
void lua_kernel_base::add_log_to_console | ( | const std::string & | msg | ) |
Definition at line 260 of file lua_kernel_base.cpp.
References cmd_log_, DBG_LUA, and wfl::msg().
|
inline |
Definition at line 80 of file lua_kernel_base.hpp.
References registered_widget_definitions_.
|
inline |
Definition at line 61 of file lua_kernel_base.hpp.
References cmd_log_, and lua_kernel_base::command_log::log_.
Referenced by gui2::dialogs::lua_interpreter::lua_model::clear_log().
std::vector< std::string > lua_kernel_base::get_attribute_names | ( | const std::string & | input | ) |
Gets all attribute names of an extended variable name.
This is useful for tab completion.
Definition at line 1422 of file lua_kernel_base.cpp.
References c, gui2::tip_of_the_day::load(), LOG_LUA, luaW_pcall(), and mState.
Referenced by gui2::dialogs::lua_interpreter::lua_model::get_attribute_names().
std::vector< std::string > lua_kernel_base::get_global_var_names | ( | ) |
Get tab completion strings.
Gets all the global variable names in the Lua environment.
This is useful for tab completion.
Definition at line 1399 of file lua_kernel_base.cpp.
References mState.
Referenced by gui2::dialogs::lua_interpreter::lua_model::get_globals().
|
inline |
Access / manipulate logging of lua kernel activities.
Definition at line 59 of file lua_kernel_base.hpp.
References cmd_log_, flush(), and lua_kernel_base::command_log::log_.
Referenced by gui2::dialogs::lua_interpreter::lua_model::lua_model().
|
inlinestatic |
Definition at line 73 of file lua_kernel_base.hpp.
References get_lua_kernel_base_ptr().
|
staticprivate |
Definition at line 1484 of file lua_kernel_base.cpp.
Referenced by get_lua_kernel(), and lua_kernel_base().
|
virtual |
Reimplemented in mapgen_lua_kernel.
Definition at line 1496 of file lua_kernel_base.cpp.
References seed_rng::next_seed().
Referenced by mapgen_lua_kernel::get_random_seed().
|
inline |
Definition at line 79 of file lua_kernel_base.hpp.
References mState.
|
protected |
Gets a list of game_config data (__dir metamethod).
Definition at line 1365 of file lua_kernel_base.cpp.
References luaW_Registry::dir(), and gameConfigReg().
|
protected |
Gets some game_config data (__index metamethod).
Definition at line 1348 of file lua_kernel_base.cpp.
References gameConfigReg(), and luaW_Registry::get().
|
protected |
Sets some game_config data (__newindex metamethod).
Definition at line 1358 of file lua_kernel_base.cpp.
References gameConfigReg(), and luaW_Registry::set().
void lua_kernel_base::interactive_run | ( | char const * | prog | ) |
Tests if a program resolves to an expression, and pretty prints it if it is, otherwise it runs it normally.
Throws exceptions.
Definition at line 1132 of file lua_kernel_base.cpp.
References cmd_log_, i, Interp, load_string(), luaW_getglobal(), mState, protected_call(), throw_exception(), and throwing_run().
Referenced by gui2::dialogs::lua_interpreter::lua_model::execute().
|
protected |
Loads and executes a Lua file.
Definition at line 1181 of file lua_kernel_base.cpp.
References lua_fileops::load_file().
|
protected |
Definition at line 1244 of file lua_kernel_base.cpp.
References lua_push(), and my_name().
|
protected |
Replacement print function – instead of printing to std::cout, print to the command log.
Intended to be bound to this' command_log at registration time.
Definition at line 213 of file lua_kernel_base.cpp.
|
protected |
Loads and executes a Lua file, if there is no corresponding entry in wesnoth.package.
Stores the result of the script in wesnoth.package and returns it.
Definition at line 1201 of file lua_kernel_base.cpp.
References DBG_LUA, game_config::debug_lua, lua_fileops::load_file(), log_error(), and protected_call().
Referenced by lua_kernel_base().
int lua_kernel_base::intf_show_lua_console | ( | lua_State * | L | ) |
Definition at line 320 of file lua_kernel_base.cpp.
References cmd_log_, lua_kernel_base::command_log::external_log_, log_error(), and lua_gui2::show_lua_console().
Referenced by lua_gui2::luaW_open().
void lua_kernel_base::load_core | ( | ) |
Loads the "core" library into the Lua environment.
Without this, most Wesnoth Lua won't work. Cannot be called from the constructor because it needs to call virtual functions.
Definition at line 1383 of file lua_kernel_base.cpp.
References cmd_log_, luaW_getglobal(), mState, and protected_call().
Referenced by lua_map_generator::lua_map_generator().
void lua_kernel_base::load_package | ( | ) |
Loads the package
library into lua environment.
Loads the "package" package into the Lua environment.
Only in allow in unsafe
modes.
This action is inherently unsafe, as Lua scripts will now be able to load C libraries on their own, hence granting them the same privileges as the Wesnoth binary itself.
Definition at line 1375 of file lua_kernel_base.cpp.
References mState.
Referenced by game_launcher::init_lua_script().
|
protectedvirtual |
Definition at line 1024 of file lua_kernel_base.cpp.
References load_string(), and log_error().
|
protected |
Definition at line 1068 of file lua_kernel_base.cpp.
References wfl::msg(), and mState.
Referenced by interactive_run(), load_string(), mapgen_lua_kernel::run_generator(), game_lua_kernel::save_wml_event(), and throwing_run().
|
virtual |
Error reporting mechanisms, used by virtual methods protected_call and load_string.
Reimplemented in game_lua_kernel.
Definition at line 1008 of file lua_kernel_base.cpp.
References ERR_LUA, and wfl::msg().
Referenced by intf_require(), intf_show_lua_console(), application_lua_kernel::load_script_from_file(), application_lua_kernel::load_script_from_string(), load_string(), game_lua_kernel::log_error(), lua_kernel_base(), protected_call(), and run().
|
inlinevirtual |
User-visible name of the lua kernel that they are talking to.
Reimplemented in game_lua_kernel, mapgen_lua_kernel, and application_lua_kernel.
Definition at line 56 of file lua_kernel_base.hpp.
Referenced by gui2::dialogs::lua_interpreter::lua_model::get_name(), intf_kernel_type(), and lua_kernel_base().
|
protectedvirtual |
Definition at line 1018 of file lua_kernel_base.cpp.
References log_error(), and protected_call().
|
protected |
Definition at line 1030 of file lua_kernel_base.cpp.
References mState.
Referenced by interactive_run(), intf_require(), load_core(), application_lua_kernel::load_script_from_file(), application_lua_kernel::load_script_from_string(), lua_kernel_base(), protected_call(), mapgen_lua_kernel::run_generator(), and throwing_run().
|
staticprotected |
Definition at line 1035 of file lua_kernel_base.cpp.
References luaW_pcall_internal(), and wfl::msg().
void lua_kernel_base::run | ( | char const * | prog, |
const std::string & | name, | ||
int | nArgs = 0 |
||
) |
Runs a plain script.
Doesn't throw lua_error.
Definition at line 1121 of file lua_kernel_base.cpp.
References cmd_log_, e, log_error(), and throwing_run().
Referenced by game_launcher::init_lua_script(), run_lua_tag(), and SYNCED_COMMAND_HANDLER_FUNCTION().
void lua_kernel_base::run_lua_tag | ( | const config & | cfg | ) |
Runs a [lua] tag.
Doesn't throw lua_error.
Definition at line 1095 of file lua_kernel_base.cpp.
References luaW_pushconfig(), mState, config::optional_child(), and run().
Referenced by game_lua_kernel::initialize().
|
inline |
Definition at line 64 of file lua_kernel_base.hpp.
References cmd_log_, and lua_kernel_base::command_log::external_log_.
Referenced by gui2::dialogs::lua_interpreter::lua_model::lua_model(), and gui2::dialogs::lua_interpreter::lua_model::~lua_model().
|
virtual |
Definition at line 1013 of file lua_kernel_base.cpp.
References wfl::msg().
Referenced by interactive_run(), mapgen_lua_kernel::run_generator(), and throwing_run().
void lua_kernel_base::throwing_run | ( | char const * | prog, |
const std::string & | name, | ||
int | nArgs, | ||
bool | in_interpreter = false |
||
) |
Runs a plain script, but reports errors by throwing lua_error.
Definition at line 1106 of file lua_kernel_base.cpp.
References cmd_log_, Interp, load_string(), mState, protected_call(), and throw_exception().
Referenced by interactive_run(), and run().
|
protected |
Definition at line 114 of file lua_kernel_base.hpp.
Referenced by add_log(), add_log_to_console(), application_lua_kernel::application_lua_kernel(), clear_log(), game_lua_kernel::game_lua_kernel(), get_log(), game_lua_kernel::initialize(), interactive_run(), intf_print(), intf_show_lua_console(), load_core(), lua_kernel_base(), mapgen_lua_kernel::mapgen_lua_kernel(), run(), set_external_log(), and throwing_run().
|
protected |
Definition at line 82 of file lua_kernel_base.hpp.
Referenced by application_lua_kernel::application_lua_kernel(), game_lua_kernel::apply_effect(), game_lua_kernel::clear_wml_event(), game_lua_kernel::create_lua_ai_action_handler(), game_lua_kernel::create_lua_ai_context(), mapgen_lua_kernel::create_map(), mapgen_lua_kernel::create_scenario(), game_lua_kernel::custom_command(), game_lua_kernel::game_lua_kernel(), get_attribute_names(), get_global_var_names(), get_state(), game_lua_kernel::initialize(), interactive_run(), load_core(), game_lua_kernel::load_game(), load_package(), application_lua_kernel::load_script_from_file(), application_lua_kernel::load_script_from_string(), load_string(), lua_kernel_base(), mapgen_lua_kernel::mapgen_lua_kernel(), game_lua_kernel::mouse_button_callback(), game_lua_kernel::mouse_over_hex_callback(), protected_call(), game_lua_kernel::push_builtin_effect(), game_lua_kernel::run_event(), game_lua_kernel::run_filter(), mapgen_lua_kernel::run_generator(), run_lua_tag(), game_lua_kernel::run_wml_action(), game_lua_kernel::run_wml_conditional(), game_lua_kernel::run_wml_event(), game_lua_kernel::save_game(), game_lua_kernel::save_wml_event(), game_lua_kernel::select_hex_callback(), game_lua_kernel::set_wml_action(), game_lua_kernel::set_wml_condition(), throwing_run(), and ~lua_kernel_base().
|
private |
Definition at line 146 of file lua_kernel_base.hpp.
Referenced by add_widget_definition(), and ~lua_kernel_base().