The Battle for Wesnoth  1.15.0+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 "random.hpp"
#include "seed_rng.hpp"
#include "deprecation.hpp"
#include "language.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_map_location_ops.hpp"
#include "scripting/lua_rng.hpp"
#include "scripting/push_check.hpp"
#include "game_version.hpp"
#include "picture.hpp"
#include "formula/string_utils.hpp"
#include "serialization/string_utils.hpp"
#include "serialization/schema_validator.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.hpp"
#include "utils/functional.hpp"
#include "utils/name_generator.hpp"
#include "utils/markov_generator.hpp"
#include "utils/context_free_grammar_generator.hpp"
#include "variable.hpp"
#include <cstring>
#include <exception>
#include <new>
#include <string>
#include <sstream>
#include <vector>
#include <fstream>
#include "lua/lauxlib.h"
#include "lua/lua.h"
#include "lua/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

static int intf_compare_versions (lua_State *L)
 Compares 2 version strings - which is newer. More...
 
static int intf_load (lua_State *L)
 Replacement load function. 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_random (lua_State *L)
 Returns a random numer, same interface as math.random. More...
 
static int intf_wml_matches_filter (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_get_image_size (lua_State *L)
 Gets the dimension of an image. More...
 
static int intf_get_time_stamp (lua_State *L)
 Returns the time stamp, exactly as [set_variable] time=stamp does. More...
 
static int intf_format (lua_State *L)
 
template<bool conjunct>
static int intf_format_list (lua_State *L)
 
static int intf_get_language (lua_State *L)
 
static int intf_wml_tostring (lua_State *L)
 Dumps a wml table or userdata wml object into a pretty string. More...
 
static int intf_load_wml (lua_State *L)
 Loads a WML file into a config. More...
 
static int intf_parse_wml (lua_State *L)
 Parses a WML string into a config; does not preprocess or validate. More...
 
static int intf_clone_wml (lua_State *L)
 Returns a clone (deep copy) of the passed config, which can be either a normal config or a vconfig If it is a vconfig, the underlying config is also cloned. 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"
 

Macro Definition Documentation

◆ DBG_LUA

#define DBG_LUA   LOG_STREAM(debug, log_scripting_lua)

◆ ERR_LUA

#define ERR_LUA   LOG_STREAM(err, log_scripting_lua)

Definition at line 71 of file lua_kernel_base.cpp.

Referenced by lua_kernel_base::log_error().

◆ LOG_LUA

#define LOG_LUA   LOG_STREAM(info, log_scripting_lua)

◆ WRN_LUA

#define WRN_LUA   LOG_STREAM(warn, log_scripting_lua)

Definition at line 70 of file lua_kernel_base.cpp.

Typedef Documentation

◆ member_callback

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

Definition at line 504 of file lua_kernel_base.cpp.

Function Documentation

◆ dispatch()

template<member_callback method>
int dispatch ( lua_State L)

Definition at line 507 of file lua_kernel_base.cpp.

◆ impl_name_generator_call()

static int impl_name_generator_call ( lua_State L)
static

◆ impl_name_generator_collect()

static int impl_name_generator_collect ( lua_State L)
static

◆ intf_clone_wml()

static int intf_clone_wml ( lua_State L)
static

Returns a clone (deep copy) of the passed config, which can be either a normal config or a vconfig If it is a vconfig, the underlying config is also cloned.

  • Arg 1: a config
  • Ret: the cloned config

Definition at line 487 of file lua_kernel_base.cpp.

References vconfig::get_config(), luaW_checkconfig(), luaW_pushconfig(), and luaW_pushvconfig().

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_compare_versions()

static int intf_compare_versions ( lua_State L)
static

Compares 2 version strings - which is newer.

  • Args 1,3: version strings
  • Arg 2: comparison operator (string)
  • Ret 1: comparison result

Definition at line 84 of file lua_kernel_base.cpp.

References do_version_check(), lua_pushboolean(), luaL_argerror(), luaL_checkstring, OP_INVALID, and parse_version_op().

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 327 of file lua_kernel_base.cpp.

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

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_format()

static int intf_format ( lua_State L)
static

◆ intf_format_list()

template<bool conjunct>
static int intf_format_list ( lua_State L)
static

◆ intf_get_image_size()

static int intf_get_image_size ( lua_State L)
static

Gets the dimension of an image.

  • Arg 1: string.
  • Ret 1: width.
  • Ret 2: height.

Definition at line 349 of file lua_kernel_base.cpp.

References image::locator::file_exists(), image::get_image(), lua_pushinteger(), luaL_checkstring, and s.

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_get_language()

static int intf_get_language ( lua_State L)
static

Definition at line 391 of file lua_kernel_base.cpp.

References get_language(), and lua_push().

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_get_time_stamp()

static int intf_get_time_stamp ( lua_State L)
static

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

  • Ret 1: integer

Definition at line 363 of file lua_kernel_base.cpp.

References lua_pushinteger().

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 137 of file lua_kernel_base.cpp.

References lua_insert, lua_isnone, LUA_OK, lua_pop, lua_pushnil(), lua_pushvalue(), lua_setupvalue(), luaL_argerror(), luaL_checkstring, luaL_loadbufferx(), luaL_optstring, and name().

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_load_wml()

static int intf_load_wml ( lua_State L)
static

Loads a WML file into a config.

  • Arg 1: WML file path
  • Arg 2: (optional) Array of preprocessor defines, or false to skip preprocessing (true is also valid)
  • Arg 3: (optional) Path to a schema file for validation (omit for no validation)
  • Ret: config

Definition at line 417 of file lua_kernel_base.cpp.

References config::get(), filesystem::get_wml_location(), i, lua_geti(), lua_isnoneornil, lua_isstring(), lua_len(), lua_pop, LUA_TBOOLEAN, lua_tonumber, lua_tostring, LUA_TTABLE, LUA_TUSERDATA, lua_type(), luaL_argerror(), luaL_checkstring, luaL_optstring, luaW_pushconfig(), luaW_toboolean(), n, preprocess_file(), and read().

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 301 of file lua_kernel_base.cpp.

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

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_name_generator()

static int intf_name_generator ( lua_State L)
static

◆ intf_parse_wml()

static int intf_parse_wml ( lua_State L)
static

Parses a WML string into a config; does not preprocess or validate.

  • Arg 1: WML string
  • Ret: config

Definition at line 466 of file lua_kernel_base.cpp.

References config::get(), filesystem::get_wml_location(), luaL_checkstring, luaL_optstring, luaW_pushconfig(), and read().

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_random()

static int intf_random ( lua_State L)
static

Returns a random numer, same interface as math.random.

Definition at line 261 of file lua_kernel_base.cpp.

References randomness::generator, lua_isnoneornil, lua_isnumber(), lua_push(), luaL_argerror(), and randomness::rng::next_random().

Referenced by lua_kernel_base::lua_kernel_base().

◆ intf_wml_matches_filter()

static int intf_wml_matches_filter ( lua_State L)
static

◆ intf_wml_tostring()

static int intf_wml_tostring ( lua_State L)
static

Dumps a wml table or userdata wml object into a pretty string.

  • Arg 1: wml table or vconfig userdata
  • Ret 1: string

Definition at line 402 of file lua_kernel_base.cpp.

References lua_pushstring(), luaW_checkconfig(), and write().

Referenced by lua_kernel_base::lua_kernel_base().

Variable Documentation

◆ Gen

const char* Gen = "name generator"
static

Definition at line 74 of file lua_kernel_base.cpp.

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

◆ log_scripting_lua

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

◆ log_user

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

Referenced by intf_log().