The Battle for Wesnoth  1.19.1+dev
Macros | Typedefs | Functions | Variables
lua_kernel_base.cpp File Reference
#include "scripting/lua_kernel_base.hpp"
#include "game_config.hpp"
#include "game_errors.hpp"
#include "gui/core/gui_definition.hpp"
#include "log.hpp"
#include "lua_jailbreak_exception.hpp"
#include "seed_rng.hpp"
#include "deprecation.hpp"
#include "language.hpp"
#include "team.hpp"
#include "scripting/lua_color.hpp"
#include "scripting/lua_common.hpp"
#include "scripting/lua_cpp_function.hpp"
#include "scripting/lua_fileops.hpp"
#include "scripting/lua_formula_bridge.hpp"
#include "scripting/lua_gui2.hpp"
#include "scripting/lua_wml.hpp"
#include "scripting/lua_stringx.hpp"
#include "scripting/lua_map_location_ops.hpp"
#include "scripting/lua_mathx.hpp"
#include "scripting/lua_rng.hpp"
#include "scripting/lua_widget.hpp"
#include "scripting/push_check.hpp"
#include "game_version.hpp"
#include <functional>
#include "utils/name_generator.hpp"
#include "utils/markov_generator.hpp"
#include "utils/context_free_grammar_generator.hpp"
#include "utils/scope_exit.hpp"
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <numeric>
#include "lua/wrapper_lualib.h"
Include dependency graph for lua_kernel_base.cpp:

Go to the source code of this file.

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)
 

Typedefs

typedef int(lua_kernel_base::* member_callback) (lua_State *L)
 

Functions

template<VERSION_COMP_OP vop>
static int impl_version_compare (lua_State *L)
 Compares two versions. More...
 
static int impl_version_get (lua_State *L)
 Decomposes a version into its component parts. More...
 
static int impl_version_dir (lua_State *L)
 
static int impl_version_finalize (lua_State *L)
 Destroy a version. More...
 
static int impl_version_tostring (lua_State *L)
 Convert a version to string form. More...
 
static int intf_make_version (lua_State *L)
 Builds a version from its component parts, or parses it from a string. More...
 
static int intf_current_version (lua_State *L)
 Returns the current Wesnoth version. More...
 
static void impl_warn (void *p, const char *msg, int tocont)
 
static int intf_load (lua_State *L)
 Replacement load function. More...
 
static int intf_pcall (lua_State *L)
 Wrapper for pcall and xpcall functions to rethrow jailbreak exceptions. More...
 
static int impl_name_generator_call (lua_State *L)
 
static int impl_name_generator_collect (lua_State *L)
 
static int intf_name_generator (lua_State *L)
 
static int intf_log (lua_State *L)
 Logs a message Arg 1: (optional) Logger Arg 2: Message. More...
 
static int intf_deprecated_message (lua_State *L)
 Logs a deprecation message. More...
 
static int intf_named_tuple (lua_State *L)
 Converts a Lua array to a named tuple. More...
 
static int intf_parse_shroud_bitmap (lua_State *L)
 
static int intf_make_shroud_bitmap (lua_State *L)
 
static int intf_ms_since_init (lua_State *L)
 Returns the time stamp, exactly as [set_variable] time=stamp does. More...
 
static int intf_get_language (lua_State *L)
 
static void dir_meta_helper (lua_State *L, std::vector< std::string > &keys)
 
static int impl_is_deprecated (lua_State *L)
 
static int impl_get_dir_suffix (lua_State *L)
 
std::vector< std::string > luaW_get_attributes (lua_State *L, int idx)
 This function does the actual work of grabbing all the attribute names. More...
 
static int intf_object_dir (lua_State *L)
 Prints out a list of keys available in an object. More...
 
template<member_callback method>
int dispatch (lua_State *L)
 

Variables

static lg::log_domain log_scripting_lua ("scripting/lua")
 
static lg::log_domain log_user ("scripting/lua/user")
 
static const char * Gen = "name generator"
 
static const char * Version = "version"
 
static const char * Interp = "lua interpreter"
 

Macro Definition Documentation

◆ DBG_LUA

#define DBG_LUA   LOG_STREAM(debug, log_scripting_lua)

Definition at line 64 of file lua_kernel_base.cpp.

◆ ERR_LUA

#define ERR_LUA   LOG_STREAM(err, log_scripting_lua)

Definition at line 67 of file lua_kernel_base.cpp.

◆ LOG_LUA

#define LOG_LUA   LOG_STREAM(info, log_scripting_lua)

Definition at line 65 of file lua_kernel_base.cpp.

◆ WRN_LUA

#define WRN_LUA   LOG_STREAM(warn, log_scripting_lua)

Definition at line 66 of file lua_kernel_base.cpp.

Typedef Documentation

◆ member_callback

typedef int(lua_kernel_base::* member_callback) (lua_State *L)

Definition at line 720 of file lua_kernel_base.cpp.

Function Documentation

◆ dir_meta_helper()

static void dir_meta_helper ( lua_State *  L,
std::vector< std::string > &  keys 
)
static

Definition at line 527 of file lua_kernel_base.cpp.

References lua_push().

Referenced by luaW_get_attributes().

◆ dispatch()

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

Definition at line 723 of file lua_kernel_base.cpp.

◆ impl_get_dir_suffix()

static int impl_get_dir_suffix ( lua_State *  L)
static

Definition at line 566 of file lua_kernel_base.cpp.

Referenced by intf_object_dir().

◆ impl_is_deprecated()

static int impl_is_deprecated ( lua_State *  L)
static

Definition at line 548 of file lua_kernel_base.cpp.

References luaW_toboolean().

Referenced by luaW_get_attributes().

◆ impl_name_generator_call()

static int impl_name_generator_call ( lua_State *  L)
static

Definition at line 331 of file lua_kernel_base.cpp.

References name_generator::generate().

Referenced by lua_kernel_base::lua_kernel_base().

◆ impl_name_generator_collect()

static int impl_name_generator_collect ( lua_State *  L)
static

Definition at line 338 of file lua_kernel_base.cpp.

References name_generator::~name_generator().

Referenced by lua_kernel_base::lua_kernel_base().

◆ impl_version_compare()

template<VERSION_COMP_OP vop>
static int impl_version_compare ( lua_State *  L)
static

Compares two versions.

  • Args 1,2: version strings
  • Ret 1: comparison result

Definition at line 83 of file lua_kernel_base.cpp.

References do_version_check(), and Version.

◆ impl_version_dir()

static int impl_version_dir ( lua_State *  L)
static

Definition at line 123 of file lua_kernel_base.cpp.

References lua_push().

Referenced by intf_make_version().

◆ impl_version_finalize()

static int impl_version_finalize ( lua_State *  L)
static

Destroy a version.

Definition at line 133 of file lua_kernel_base.cpp.

References Version.

Referenced by intf_make_version().

◆ impl_version_get()

static int impl_version_get ( lua_State *  L)
static

◆ impl_version_tostring()

static int impl_version_tostring ( lua_State *  L)
static

Convert a version to string form.

Definition at line 143 of file lua_kernel_base.cpp.

References lua_push(), version_info::str(), and Version.

Referenced by intf_make_version().

◆ impl_warn()

static void impl_warn ( void *  p,
const char *  msg,
int  tocont 
)
static

Definition at line 242 of file lua_kernel_base.cpp.

References lua_push(), luaW_getglobal(), wfl::msg(), and p.

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_current_version()

static int intf_current_version ( lua_State *  L)
static

Returns the current Wesnoth version.

Definition at line 201 of file lua_kernel_base.cpp.

References intf_make_version(), lua_push(), and game_config::wesnoth_version.

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_deprecated_message()

static int intf_deprecated_message ( lua_State *  L)
static

Logs a deprecation message.

See deprecation.cpp for details Arg 1: Element to be deprecated. Arg 2: Deprecation level. Arg 3: Version when element may be removed. Arg 4: Additional detail message.

Definition at line 441 of file lua_kernel_base.cpp.

References deprecated_message(), game_config::images::level, lua_push(), luaW_checktstring(), wfl::msg(), REMOVED, version_info::str(), and game_config::wesnoth_version.

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_get_language()

static int intf_get_language ( lua_State *  L)
static

Definition at line 521 of file lua_kernel_base.cpp.

References get_language(), and lua_push().

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_load()

static int intf_load ( lua_State *  L)
static

Replacement load function.

Mostly the same as regular load, but disallows loading binary chunks due to CVE-2018-1999023.

Definition at line 268 of file lua_kernel_base.cpp.

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_log()

static int intf_log ( lua_State *  L)
static

Logs a message Arg 1: (optional) Logger Arg 2: Message.

Definition at line 415 of file lua_kernel_base.cpp.

References debug, lg::err(), lg::info(), LOG_STREAM, log_user, wfl::msg(), and lg::warn().

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_make_shroud_bitmap()

static int intf_make_shroud_bitmap ( lua_State *  L)
static

◆ intf_make_version()

static int intf_make_version ( lua_State *  L)
static

Builds a version from its component parts, or parses it from a string.

Definition at line 153 of file lua_kernel_base.cpp.

References impl_version_dir(), impl_version_finalize(), impl_version_get(), impl_version_tostring(), and Version.

Referenced by intf_current_version(), and lua_kernel_base::lua_kernel_base().

◆ intf_ms_since_init()

static int intf_ms_since_init ( lua_State *  L)
static

Returns the time stamp, exactly as [set_variable] time=stamp does.

  • Ret 1: integer

Definition at line 516 of file lua_kernel_base.cpp.

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_name_generator()

static int intf_name_generator ( lua_State *  L)
static

◆ intf_named_tuple()

static int intf_named_tuple ( lua_State *  L)
static

Converts a Lua array to a named tuple.

Arg 1: A Lua array Arg 2: An array of strings Ret: A copy of arg 1 that's now a named tuple with the names in arg 2. The copy will only include the array portion of the input array. Any non-integer keys or non-consecutive keys will be gone. Note: This exists so that wml.tag can use it but is not really intended as a public API.

Definition at line 467 of file lua_kernel_base.cpp.

References i, luaW_push_namedtuple(), luaW_type_error(), and names.

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_object_dir()

static int intf_object_dir ( lua_State *  L)
static

Prints out a list of keys available in an object.

A list of keys is gathered from the following sources:

  • For a table, all keys defined in the table
  • Any keys accessible through the metatable chain (if __index on the metatable is a table)
  • The output of the __dir metafunction
  • Filtering out any keys beginning with two underscores
  • Filtering out any keys for which object[key].__deprecated exists and is true The list is then sorted alphabetically and formatted into columns.
  • Arg 1: Any object
  • Arg 2: (optional) Function to use for output; defaults to _G.print

Definition at line 671 of file lua_kernel_base.cpp.

References flush(), i, impl_get_dir_suffix(), draw::line(), lua_push(), luaW_get_attributes(), luaW_getglobal(), and ON_SCOPE_EXIT.

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_parse_shroud_bitmap()

static int intf_parse_shroud_bitmap ( lua_State *  L)
static

◆ intf_pcall()

static int intf_pcall ( lua_State *  L)
static

Wrapper for pcall and xpcall functions to rethrow jailbreak exceptions.

Definition at line 305 of file lua_kernel_base.cpp.

References lua_jailbreak_exception::rethrow().

Referenced by lua_kernel_base::lua_kernel_base().

◆ luaW_get_attributes()

std::vector<std::string> luaW_get_attributes ( lua_State *  L,
int  idx 
)

This function does the actual work of grabbing all the attribute names.

It's a separate function so that it can be used by tab-completion as well.

Definition at line 595 of file lua_kernel_base.cpp.

References dir_meta_helper(), impl_is_deprecated(), lua_push(), luaW_toboolean(), and ON_SCOPE_EXIT.

Referenced by lua_widget::impl_widget_dir(), and intf_object_dir().

Variable Documentation

◆ Gen

const char* Gen = "name generator"
static

Definition at line 70 of file lua_kernel_base.cpp.

Referenced by intf_name_generator(), and lua_kernel_base::lua_kernel_base().

◆ Interp

const char* Interp = "lua interpreter"
static

◆ log_scripting_lua

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

◆ log_user

lg::log_domain log_user("scripting/lua/user") ( "scripting/lua/user"  )
static

Referenced by intf_log().

◆ Version

const char* Version = "version"
static