The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Private Member Functions | List of all members
lua_kernel_base Class Reference

#include <lua_kernel_base.hpp>

Inheritance diagram for lua_kernel_base:
Inheritance graph

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::stringget_global_var_names ()
 Gets all the global variable names in the Lua environment. More...
 
std::vector< std::stringget_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_Stateget_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_StatemState
 
CVideovideo_
 
command_log cmd_log_
 

Static Private Member Functions

static lua_kernel_base *& get_lua_kernel_base_ptr (lua_State *L)
 

Detailed Description

Definition at line 28 of file lua_kernel_base.hpp.

Member Typedef Documentation

typedef std::function<void(char const*, char const*)> lua_kernel_base::error_handler

Definition at line 59 of file lua_kernel_base.hpp.

Constructor & Destructor Documentation

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

lua_kernel_base::~lua_kernel_base ( )
virtual

Definition at line 474 of file lua_kernel_base.cpp.

References lua_close(), and mState.

Member Function Documentation

void lua_kernel_base::clear_log ( )
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().

const std::stringstream& lua_kernel_base::get_log ( )
inline
template<typename T >
static T& lua_kernel_base::get_lua_kernel ( lua_State L)
inlinestatic

Definition at line 64 of file lua_kernel_base.hpp.

References get_lua_kernel_base_ptr().

lua_kernel_base *& lua_kernel_base::get_lua_kernel_base_ptr ( lua_State L)
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().

boost::uint32_t lua_kernel_base::get_random_seed ( )
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().

lua_State* lua_kernel_base::get_state ( )
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().

int lua_kernel_base::intf_dofile ( lua_State L)
protected

Loads and executes a Lua file.

  • Arg 1: string containing the file name.
  • Ret *: values returned by executing the file body.

Definition at line 634 of file lua_kernel_base.cpp.

References lua_fileops::load_file(), log_error(), lua_gettop(), LUA_MULTRET, and protected_call().

int lua_kernel_base::intf_print ( lua_State L)
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 95 of file lua_kernel_base.cpp.

References cmd_log_, DBG_LUA, i, lua_gettop(), and lua_tostring.

int lua_kernel_base::intf_require ( lua_State L)
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.

  • Arg 1: string containing the file name.
  • Ret 1: value returned by the script.

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

int lua_kernel_base::intf_show_dialog ( lua_State L)
protected

Definition at line 119 of file lua_kernel_base.cpp.

References ERR_LUA, lua_error(), lua_gui2::show_dialog(), and video_.

int lua_kernel_base::intf_show_lua_console ( lua_State L)
protected
int lua_kernel_base::intf_show_message_dialog ( lua_State L)
protected

Definition at line 130 of file lua_kernel_base.cpp.

References ERR_LUA, lua_error(), lua_gui2::show_message_dialog(), and video_.

int lua_kernel_base::intf_show_popup_dialog ( lua_State L)
protected

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

bool lua_kernel_base::load_string ( char const *  prog,
error_handler  e_h 
)
protected
bool lua_kernel_base::load_string ( char const *  prog)
protectedvirtual

Definition at line 495 of file lua_kernel_base.cpp.

References load_string(), and log_error().

void lua_kernel_base::log_error ( char const *  msg,
char const *  context = "Lua error" 
)
virtual
virtual std::string lua_kernel_base::my_name ( )
inlinevirtual
bool lua_kernel_base::protected_call ( int  nArgs,
int  nRets,
error_handler  e_h 
)
protected
bool lua_kernel_base::protected_call ( lua_State L,
int  nArgs,
int  nRets,
error_handler  e_h 
)
staticprotected
bool lua_kernel_base::protected_call ( int  nArgs,
int  nRets 
)
protectedvirtual

Definition at line 489 of file lua_kernel_base.cpp.

References log_error(), and protected_call().

void lua_kernel_base::run ( char const *  prog,
int  nArgs = 0 
)

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

void lua_kernel_base::run_lua_tag ( const config cfg)

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

void lua_kernel_base::set_external_log ( std::ostream *  lg)
inline
void lua_kernel_base::set_video ( CVideo ptr)
inline

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

void lua_kernel_base::throw_exception ( char const *  msg,
char const *  context = "Lua error" 
)
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().

void lua_kernel_base::throwing_run ( char const *  prog,
int  nArgs 
)

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

Member Data Documentation

command_log lua_kernel_base::cmd_log_
protected
lua_State* lua_kernel_base::mState
protected
CVideo* lua_kernel_base::video_
protected

The documentation for this class was generated from the following files: