#include <lua_kernel_base.hpp>
Classes | |
struct | command_log |
Public Types | |
typedef std::function< void(char const *, char const *)> | error_handler |
Public Member Functions | |
lua_kernel_base (CVideo *ptr) | |
virtual | ~lua_kernel_base () |
void | run_lua_tag (const config &cfg) |
Runs a [lua] tag. More... | |
void | run (char const *prog, int nArgs=0) |
Runs a plain script. More... | |
void | throwing_run (char const *prog, int nArgs) |
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" package into the Lua environment. More... | |
std::vector< std::string > | get_global_var_names () |
Gets all the global variable names in the Lua environment. 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 () |
const std::stringstream & | get_log () |
void | clear_log () |
void | set_external_log (std::ostream *lg) |
virtual void | log_error (char const *msg, char const *context="Lua error") |
virtual void | throw_exception (char const *msg, char const *context="Lua error") |
void | set_video (CVideo *ptr) |
virtual boost::uint32_t | get_random_seed () |
lua_State * | get_state () |
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... | |
int | intf_show_dialog (lua_State *L) |
int | intf_show_message_dialog (lua_State *L) |
int | intf_show_popup_dialog (lua_State *L) |
int | intf_show_lua_console (lua_State *L) |
bool | protected_call (int nArgs, int nRets, error_handler) |
bool | load_string (char const *prog, error_handler) |
virtual bool | protected_call (int nArgs, int nRets) |
virtual bool | load_string (char const *prog) |
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... | |
Static Protected Member Functions | |
static bool | protected_call (lua_State *L, int nArgs, int nRets, error_handler) |
Protected Attributes | |
lua_State * | mState |
CVideo * | video_ |
command_log | cmd_log_ |
Static Private Member Functions | |
static lua_kernel_base *& | get_lua_kernel_base_ptr (lua_State *L) |
Definition at line 28 of file lua_kernel_base.hpp.
typedef std::function<void(char const*, char const*)> lua_kernel_base::error_handler |
Definition at line 59 of file lua_kernel_base.hpp.
lua_kernel_base::lua_kernel_base | ( | CVideo * | ptr | ) |
Definition at line 258 of file lua_kernel_base.cpp.
References cmd_log_, executeKey, luaL_Reg::func, Gen, random_new::generator, get_lua_kernel_base_ptr(), impl_name_generator_call(), impl_name_generator_collect(), lua_gui2::intf_add_dialog_tree_node(), intf_compare_versions(), lua_formula_bridge::intf_compile_formula(), lua_map_location::intf_distance_between(), lua_formula_bridge::intf_eval_formula(), lua_map_location::intf_get_adjacent_tiles(), lua_gui2::intf_get_dialog_value(), lua_map_location::intf_get_direction(), lua_map_location::intf_get_in_basis_N_NE(), lua_map_location::intf_get_relative_dir(), lua_fileops::intf_have_file(), intf_name_generator(), lua_map_location::intf_parse_direction(), lua_fileops::intf_read_file(), lua_gui2::intf_remove_dialog_item(), intf_require(), lua_map_location::intf_rotate_right_around_center(), lua_gui2::intf_set_dialog_active(), lua_gui2::intf_set_dialog_callback(), lua_gui2::intf_set_dialog_canvas(), lua_gui2::intf_set_dialog_focus(), lua_gui2::intf_set_dialog_markup(), lua_gui2::intf_set_dialog_value(), lua_gui2::intf_set_dialog_visible(), lua_common::intf_textdomain(), lua_map_location::intf_tiles_adjacent(), lua_common::intf_tovconfig(), lua_map_location::intf_vector_negation(), lua_map_location::intf_vector_sum(), lua_map_location::intf_vector_zero(), lua_map_location::intf_write_direction(), lua_rng::load_tables(), log_error(), lua_getfield(), lua_getglobal(), lua_gettable(), lua_istable, lua_newtable, lua_next(), lua_pop, lua_pushcfunction, lua_pushlightuserdata(), lua_pushnil(), lua_pushstring(), lua_rawset(), LUA_REGISTRYINDEX, lua_remove(), lua_setfield(), lua_setglobal(), lua_settop(), lua_tostring, luaL_newmetatable(), luaL_requiref(), luaL_setfuncs(), luaopen_base(), luaopen_bit32(), luaopen_coroutine(), luaopen_debug(), luaopen_math(), luaopen_os(), luaopen_string(), luaopen_table(), mState, my_name(), protected_call(), lua_common::register_gettext_metatable(), lua_cpp::register_metatable(), lua_formula_bridge::register_metatables(), and lua_common::register_tstring_metatable().
|
virtual |
Definition at line 474 of file lua_kernel_base.cpp.
References lua_close(), and mState.
|
inline |
Definition at line 53 of file lua_kernel_base.hpp.
References cmd_log_, and lua_kernel_base::command_log::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 727 of file lua_kernel_base.cpp.
References lua_getglobal(), lua_gettop(), lua_isstring(), lua_istable, lua_isuserdata(), lua_next(), lua_pop, lua_pushnil(), lua_pushstring(), lua_rawget(), lua_settop(), lua_tostring, and mState.
Referenced by gui2::tlua_interpreter::lua_model::get_attribute_names().
std::vector< std::string > lua_kernel_base::get_global_var_names | ( | ) |
Gets all the global variable names in the Lua environment.
This is useful for tab completion.
Definition at line 704 of file lua_kernel_base.cpp.
References lua_getglobal(), lua_gettop(), lua_isstring(), lua_next(), lua_pop, lua_pushnil(), lua_settop(), lua_tostring, and mState.
Referenced by gui2::tlua_interpreter::lua_model::get_globals().
|
inline |
Definition at line 52 of file lua_kernel_base.hpp.
References cmd_log_, flush(), and lua_kernel_base::command_log::log_.
Referenced by gui2::tlua_interpreter::lua_model::lua_model().
|
inlinestatic |
Definition at line 64 of file lua_kernel_base.hpp.
References get_lua_kernel_base_ptr().
|
staticprivate |
Definition at line 766 of file lua_kernel_base.cpp.
References LUA_KERNEL_BASE_OFFSET.
Referenced by get_lua_kernel(), and lua_kernel_base().
|
virtual |
Reimplemented in mapgen_lua_kernel.
Definition at line 771 of file lua_kernel_base.cpp.
References seed_rng::next_seed().
Referenced by mapgen_lua_kernel::get_random_seed().
|
inline |
Definition at line 70 of file lua_kernel_base.hpp.
References mState.
Referenced by BOOST_AUTO_TEST_CASE().
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 611 of file lua_kernel_base.cpp.
References cmd_log_, load_string(), protected_call(), throw_exception(), and throwing_run().
Referenced by gui2::tlua_interpreter::lua_model::execute().
Loads and executes a Lua file.
Definition at line 634 of file lua_kernel_base.cpp.
References lua_fileops::load_file(), log_error(), lua_gettop(), LUA_MULTRET, and protected_call().
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 95 of file lua_kernel_base.cpp.
References cmd_log_, DBG_LUA, i, lua_gettop(), and lua_tostring.
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 650 of file lua_kernel_base.cpp.
References DBG_LUA, game_config::debug_lua, lua_fileops::load_file(), log_error(), lua_getglobal(), lua_isnil, lua_pop, lua_pushstring(), lua_pushvalue(), lua_rawget(), lua_settable(), luaL_argerror(), luaL_checkstring, and protected_call().
Referenced by lua_kernel_base().
Definition at line 119 of file lua_kernel_base.cpp.
References ERR_LUA, lua_error(), lua_gui2::show_dialog(), and video_.
Definition at line 153 of file lua_kernel_base.cpp.
References cmd_log_, ERR_LUA, lua_kernel_base::command_log::external_log_, log_error(), lua_error(), lua_gui2::show_lua_console(), and video_.
Definition at line 130 of file lua_kernel_base.cpp.
References ERR_LUA, lua_error(), lua_gui2::show_message_dialog(), and video_.
Definition at line 141 of file lua_kernel_base.cpp.
References ERR_LUA, lua_error(), lua_gui2::show_popup_dialog(), and video_.
void lua_kernel_base::load_package | ( | ) |
Loads the "package" package into the Lua environment.
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 itsef.
Definition at line 693 of file lua_kernel_base.cpp.
References lua_call, lua_pushcfunction, lua_pushstring(), luaopen_package(), and mState.
Referenced by game_launcher::init_lua_script().
|
protected |
Definition at line 551 of file lua_kernel_base.cpp.
References LUA_ERRGCMM, LUA_ERRMEM, LUA_ERRSYNTAX, LUA_OK, lua_pop, lua_tostring, luaL_loadstring(), game_logic::msg(), and mState.
Referenced by interactive_run(), load_string(), mapgen_lua_kernel::run_generator(), and throwing_run().
|
protectedvirtual |
Definition at line 495 of file lua_kernel_base.cpp.
References load_string(), and log_error().
Reimplemented in game_lua_kernel.
Definition at line 479 of file lua_kernel_base.cpp.
References ERR_LUA, and game_logic::msg().
Referenced by game_lua_kernel::initialize(), intf_dofile(), 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 |
Reimplemented in game_lua_kernel, application_lua_kernel, and mapgen_lua_kernel.
Definition at line 50 of file lua_kernel_base.hpp.
Referenced by gui2::tlua_interpreter::lua_model::get_name(), and lua_kernel_base().
|
protected |
Definition at line 501 of file lua_kernel_base.cpp.
References mState.
Referenced by game_lua_kernel::initialize(), interactive_run(), intf_dofile(), intf_require(), 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 506 of file lua_kernel_base.cpp.
References executeKey, LUA_ERRERR, LUA_ERRGCMM, LUA_ERRMEM, LUA_ERRRUN, lua_gettop(), lua_insert(), LUA_OK, lua_pcall, lua_pop, lua_pushlightuserdata(), lua_rawget(), LUA_REGISTRYINDEX, lua_remove(), lua_tostring, game_logic::msg(), and tlua_jailbreak_exception::rethrow().
Definition at line 489 of file lua_kernel_base.cpp.
References log_error(), and protected_call().
Runs a plain script.
Doesn't throw lua_error.
Definition at line 600 of file lua_kernel_base.cpp.
References cmd_log_, e, log_error(), throwing_run(), and game::error::what().
Referenced by game_launcher::init_lua_script(), run_lua_tag(), and SYNCED_COMMAND_HANDLER_FUNCTION().
Runs a [lua] tag.
Doesn't throw lua_error.
Definition at line 579 of file lua_kernel_base.cpp.
References config::child(), luaW_pushconfig(), mState, and run().
Referenced by game_lua_kernel::initialize().
|
inline |
Definition at line 54 of file lua_kernel_base.hpp.
References cmd_log_, and lua_kernel_base::command_log::external_log_.
Referenced by gui2::tlua_interpreter::lua_model::lua_model(), and gui2::tlua_interpreter::lua_model::~lua_model().
Definition at line 61 of file lua_kernel_base.hpp.
References video_.
Referenced by game_lua_kernel::set_game_display(), and lua_map_generator::user_config().
|
virtual |
Definition at line 484 of file lua_kernel_base.cpp.
References lua_error().
Referenced by interactive_run(), mapgen_lua_kernel::run_generator(), and throwing_run().
Runs a plain script, but reports errors by throwing lua_error.
Definition at line 590 of file lua_kernel_base.cpp.
References cmd_log_, load_string(), lua_insert(), mState, protected_call(), and throw_exception().
Referenced by interactive_run(), and run().
|
protected |
Definition at line 104 of file lua_kernel_base.hpp.
Referenced by clear_log(), game_lua_kernel::game_lua_kernel(), get_log(), game_lua_kernel::initialize(), interactive_run(), intf_print(), intf_show_lua_console(), lua_kernel_base(), run(), set_external_log(), and throwing_run().
|
protected |
Definition at line 72 of file lua_kernel_base.hpp.
Referenced by application_lua_kernel::application_lua_kernel(), game_lua_kernel::apply_effect(), 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::game_lua_kernel(), get_attribute_names(), get_global_var_names(), get_state(), game_lua_kernel::initialize(), 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_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::save_game(), game_lua_kernel::select_hex_callback(), game_lua_kernel::set_wml_action(), throwing_run(), and ~lua_kernel_base().
|
protected |
Definition at line 74 of file lua_kernel_base.hpp.
Referenced by intf_show_dialog(), intf_show_lua_console(), intf_show_message_dialog(), intf_show_popup_dialog(), and set_video().