The Battle for Wesnoth  1.19.7+dev
Namespaces | Macros | Functions
lua_common.hpp File Reference
#include "config.hpp"
#include "variable_info.hpp"
#include "map/location.hpp"
#include <string>
#include <string_view>
#include <vector>
Include dependency graph for lua_common.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 lua_common
 

Macros

#define deprecate_attrib(name, prefix, level, version, msg)   deprecated_message(prefix "." name, DEP_LEVEL::level, version, msg)
 
#define return_deprecated_attrib(type_macro, name, accessor, prefix, level, version, msg)
 
#define return_tstring_attrib(name, accessor)
 
#define return_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor)    return_deprecated_attrib(return_tstring_attrib, name, accessor, prefix, level, version, msg)
 
#define return_cstring_attrib(name, accessor)
 
#define return_cstring_attrib_deprecated(name, prefix, level, version, msg, accessor)    return_deprecated_attrib(return_cstring_attrib, name, accessor, prefix, level, version, msg)
 
#define return_string_attrib(name, accessor)
 
#define return_string_attrib_deprecated(name, prefix, level, version, msg, accessor)    return_deprecated_attrib(return_string_attrib, name, accessor, prefix, level, version, msg)
 
#define return_int_attrib(name, accessor)
 
#define return_int_attrib_deprecated(name, prefix, level, version, msg, accessor)    return_deprecated_attrib(return_int_attrib, name, accessor, prefix, level, version, msg)
 
#define return_float_attrib(name, accessor)
 
#define return_float_attrib_deprecated(name, prefix, level, version, msg, accessor)    return_deprecated_attrib(return_float_attrib, name, accessor, prefix, level, version, msg)
 
#define return_bool_attrib(name, accessor)
 
#define return_bool_attrib_deprecated(name, prefix, level, version, msg, accessor)    return_deprecated_attrib(return_bool_attrib, name, accessor, prefix, level, version, msg)
 
#define return_cfg_attrib(name, accessor)
 
#define return_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor)    return_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
 
#define return_cfgref_attrib(name, accessor)
 
#define return_cfgref_attrib_deprecated(name, prefix, level, version, msg, accessor)    return_deprecated_attrib(return_cfgref_attrib, name, accessor, prefix, level, version, msg)
 
#define return_vector_string_attrib(name, accessor)
 
#define return_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor)    return_deprecated_attrib(return_vector_string_attrib, name, accessor, prefix, level, version, msg)
 
#define modify_tstring_attrib(name, accessor)
 
#define modify_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor)    modify_tstring_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
 
#define modify_string_attrib(name, accessor)
 
#define modify_string_attrib_deprecated(name, prefix, level, version, msg, accessor)    modify_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
 
#define modify_int_attrib(name, accessor)
 
#define modify_int_attrib_deprecated(name, prefix, level, version, msg, accessor)    modify_int_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
 
#define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max)
 
#define modify_int_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max)    modify_int_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)
 
#define modify_float_attrib(name, accessor)
 
#define modify_float_attrib_deprecated(name, prefix, level, version, msg, accessor)    modify_float_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
 
#define modify_float_attrib_check_range(name, accessor, allowed_min, allowed_max)
 
#define modify_float_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max)    modify_float_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)
 
#define modify_bool_attrib(name, accessor)
 
#define modify_bool_attrib_deprecated(name, prefix, level, version, msg, accessor)    modify_bool_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
 
#define modify_cfg_attrib(name, accessor)
 
#define modify_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor)    modify_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
 
#define modify_vector_string_attrib(name, accessor)
 
#define modify_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor)    modify_vector_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
 

Functions

int lua_common::intf_textdomain (lua_State *L)
 Creates an interface for gettext. More...
 
int lua_common::intf_tovconfig (lua_State *L)
 Creates a vconfig containing the WML table. More...
 
std::string lua_common::register_gettext_metatable (lua_State *L)
 Adds the gettext metatable. More...
 
std::string lua_common::register_tstring_metatable (lua_State *L)
 Adds the tstring metatable. More...
 
std::string lua_common::register_vconfig_metatable (lua_State *L)
 Adds the vconfig metatable. More...
 
void * operator new (std::size_t sz, lua_State *L, int nuv=0)
 
void operator delete (void *p, lua_State *L, int nuv)
 
bool luaW_getmetafield (lua_State *L, int idx, const char *key)
 Like luaL_getmetafield, but returns false if key is an empty string or begins with two underscores. More...
 
void luaW_pushvconfig (lua_State *L, const vconfig &cfg)
 Pushes a vconfig on the top of the stack. More...
 
void luaW_pushtstring (lua_State *L, const t_string &v)
 Pushes a t_string on the top of the stack. More...
 
void luaW_pushscalar (lua_State *L, const config::attribute_value &v)
 Converts an attribute value into a Lua object pushed at the top of the stack. More...
 
bool luaW_toscalar (lua_State *L, int index, config::attribute_value &v)
 Converts the value at the top of the stack to an attribute value. More...
 
bool luaW_totstring (lua_State *L, int index, t_string &str)
 Converts a scalar to a translatable string. More...
 
t_string luaW_checktstring (lua_State *L, int index)
 Converts a scalar to a translatable string. More...
 
bool luaW_iststring (lua_State *L, int index)
 
void luaW_filltable (lua_State *L, const config &cfg)
 Converts a config object to a Lua table. More...
 
void luaW_push_namedtuple (lua_State *L, const std::vector< std::string > &names)
 Push an empty "named tuple" onto the stack. More...
 
void luaW_pushlocation (lua_State *L, const map_location &loc)
 Converts a map location object to a Lua table pushed at the top of the stack. More...
 
bool luaW_tolocation (lua_State *L, int index, map_location &loc)
 Converts an optional table or pair of integers to a map location object. More...
 
map_location luaW_checklocation (lua_State *L, int index)
 Converts an optional table or pair of integers to a map location object. More...
 
int luaW_push_locationset (lua_State *L, const std::set< map_location > &locs)
 Converts a set of map locations to a Lua table pushed at the top of the stack. More...
 
std::set< map_locationluaW_check_locationset (lua_State *L, int idx)
 Converts a table of integer pairs to a set of map location objects. More...
 
void luaW_pushconfig (lua_State *L, const config &cfg)
 Converts a config object to a Lua table pushed at the top of the stack. More...
 
bool luaW_toconfig (lua_State *L, int index, config &cfg)
 Converts an optional table or vconfig to a config object. More...
 
config luaW_checkconfig (lua_State *L, int index)
 Converts an optional table or vconfig to a config object. More...
 
bool luaW_tovconfig (lua_State *L, int index, vconfig &vcfg)
 Gets an optional vconfig from either a table or a userdata. More...
 
vconfig luaW_checkvconfig (lua_State *L, int index, bool allow_missing=false)
 Gets an optional vconfig from either a table or a userdata. More...
 
config luaW_checkconfig (lua_State *L, int index, const vconfig *&vcfg)
 Like the two-argument version, but if it was a vconfig, also returns a pointer to that vconfig. More...
 
bool luaW_getglobal (lua_State *L, const std::vector< std::string > &path)
 Pushes the value found by following the variadic names (char *), if the value is not nil. More...
 
template<typename... T>
bool luaW_getglobal (lua_State *L, T... path)
 Pushes the value found by following the variadic names (char *), if the value is not nil. More...
 
bool luaW_toboolean (lua_State *L, int n)
 
bool luaW_pushvariable (lua_State *L, variable_access_const &v)
 
bool luaW_checkvariable (lua_State *L, variable_access_create &v, int n)
 
bool luaW_tableget (lua_State *L, int index, const char *key)
 
std::string_view luaW_tostring (lua_State *L, int index)
 
std::string_view luaW_tostring_or_default (lua_State *L, int index, std::string_view def=std::string_view())
 
void chat_message (const std::string &caption, const std::string &msg)
 Displays a message in the chat window. More...
 
bool luaW_pcall (lua_State *L, int nArgs, int nRets, bool allow_wml_error=false)
 Calls a Lua function stored below its nArgs arguments at the top of the stack. More...
 
void push_error_handler (lua_State *L)
 
int luaW_pcall_internal (lua_State *L, int nArgs, int nRets)
 
int luaW_type_error (lua_State *L, int narg, const char *tname)
 
int luaW_type_error (lua_State *L, int narg, const char *kpath, const char *tname)
 

Macro Definition Documentation

◆ deprecate_attrib

#define deprecate_attrib (   name,
  prefix,
  level,
  version,
  msg 
)    deprecated_message(prefix "." name, DEP_LEVEL::level, version, msg)

Definition at line 228 of file lua_common.hpp.

◆ modify_bool_attrib

#define modify_bool_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
bool value = luaW_toboolean(L, 3); \
{accessor;} \
return 0; \
} \
} while(false)
bool luaW_toboolean(lua_State *L, int n)
Definition: lua_common.cpp:998

Definition at line 404 of file lua_common.hpp.

◆ modify_bool_attrib_deprecated

#define modify_bool_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     modify_bool_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)

Definition at line 412 of file lua_common.hpp.

◆ modify_cfg_attrib

#define modify_cfg_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
const config& cfg = luaW_checkconfig(L, 3); \
{accessor;} \
return 0; \
} \
} while(false)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
Definition: lua_common.cpp:927

Definition at line 415 of file lua_common.hpp.

◆ modify_cfg_attrib_deprecated

#define modify_cfg_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     modify_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)

Definition at line 423 of file lua_common.hpp.

◆ modify_float_attrib

#define modify_float_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
lua_Number value = luaL_checknumber(L, 3); \
{accessor;} \
return 0; \
} \
} while(false)

Definition at line 381 of file lua_common.hpp.

◆ modify_float_attrib_check_range

#define modify_float_attrib_check_range (   name,
  accessor,
  allowed_min,
  allowed_max 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
lua_Number value = luaL_checknumber(L, 3); \
if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \
{accessor;} \
return 0; \
} \
} while(false)

Definition at line 392 of file lua_common.hpp.

◆ modify_float_attrib_check_range_deprecated

#define modify_float_attrib_check_range_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor,
  allowed_min,
  allowed_max 
)     modify_float_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)

Definition at line 401 of file lua_common.hpp.

◆ modify_float_attrib_deprecated

#define modify_float_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     modify_float_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)

Definition at line 389 of file lua_common.hpp.

◆ modify_int_attrib

#define modify_int_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
int value = static_cast<int>(luaL_checknumber(L, 3)); \
{accessor;} \
return 0; \
} \
} while(false)

Definition at line 358 of file lua_common.hpp.

◆ modify_int_attrib_check_range

#define modify_int_attrib_check_range (   name,
  accessor,
  allowed_min,
  allowed_max 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
int value = static_cast<int>(luaL_checknumber(L, 3)); \
if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \
{accessor;} \
return 0; \
} \
} while(false)

Definition at line 369 of file lua_common.hpp.

◆ modify_int_attrib_check_range_deprecated

#define modify_int_attrib_check_range_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor,
  allowed_min,
  allowed_max 
)     modify_int_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)

Definition at line 378 of file lua_common.hpp.

◆ modify_int_attrib_deprecated

#define modify_int_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     modify_int_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)

Definition at line 366 of file lua_common.hpp.

◆ modify_string_attrib

#define modify_string_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
const char *value = luaL_checkstring(L, 3); \
{accessor;} \
return 0; \
} \
} while(false)

Definition at line 347 of file lua_common.hpp.

◆ modify_string_attrib_deprecated

#define modify_string_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     modify_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)

Definition at line 355 of file lua_common.hpp.

◆ modify_tstring_attrib

#define modify_tstring_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
t_string value = luaW_checktstring(L, 3); \
{accessor;} \
return 0; \
} \
} while(false)
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
Definition: lua_common.cpp:635

Definition at line 336 of file lua_common.hpp.

◆ modify_tstring_attrib_deprecated

#define modify_tstring_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     modify_tstring_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)

Definition at line 344 of file lua_common.hpp.

◆ modify_vector_string_attrib

#define modify_vector_string_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
std::vector<std::string> value; \
char const* message = "table with unnamed indices holding strings expected"; \
if (!lua_istable(L, 3)) return luaL_argerror(L, 3, message); \
unsigned length = lua_rawlen(L, 3); \
for (unsigned i = 1; i <= length; ++i) { \
lua_rawgeti(L, 3, i); \
char const* string = lua_tostring(L, 4); \
if(!string) return luaL_argerror(L, 2 + i, message); \
value.push_back(string); \
lua_pop(L, 1); \
} \
{accessor;} \
return 0; \
} \
} while(false)
std::size_t i
Definition: function.cpp:1029

Definition at line 426 of file lua_common.hpp.

◆ modify_vector_string_attrib_deprecated

#define modify_vector_string_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     modify_vector_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)

Definition at line 444 of file lua_common.hpp.

◆ return_bool_attrib

#define return_bool_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
lua_pushboolean(L, (accessor)); \
return 1; \
} \
} while(false)

Definition at line 287 of file lua_common.hpp.

◆ return_bool_attrib_deprecated

#define return_bool_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     return_deprecated_attrib(return_bool_attrib, name, accessor, prefix, level, version, msg)

Definition at line 294 of file lua_common.hpp.

◆ return_cfg_attrib

#define return_cfg_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
config cfg; \
{accessor;} \
luaW_pushconfig(L, cfg); \
return 1; \
} \
} while(false)

Definition at line 297 of file lua_common.hpp.

◆ return_cfg_attrib_deprecated

#define return_cfg_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     return_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)

Definition at line 306 of file lua_common.hpp.

◆ return_cfgref_attrib

#define return_cfgref_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
luaW_pushconfig(L, (accessor)); \
return 1; \
} \
} while(false)

Definition at line 309 of file lua_common.hpp.

◆ return_cfgref_attrib_deprecated

#define return_cfgref_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     return_deprecated_attrib(return_cfgref_attrib, name, accessor, prefix, level, version, msg)

Definition at line 316 of file lua_common.hpp.

◆ return_cstring_attrib

#define return_cstring_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
lua_pushstring(L, (accessor)); \
return 1; \
} \
} while(false)

Definition at line 246 of file lua_common.hpp.

◆ return_cstring_attrib_deprecated

#define return_cstring_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     return_deprecated_attrib(return_cstring_attrib, name, accessor, prefix, level, version, msg)

Definition at line 253 of file lua_common.hpp.

◆ return_deprecated_attrib

#define return_deprecated_attrib (   type_macro,
  name,
  accessor,
  prefix,
  level,
  version,
  msg 
)
Value:
type_macro(name, ( \
deprecate_attrib(name, prefix, level, version, msg), \
accessor \
))
#define deprecate_attrib(name, prefix, level, version, msg)
Definition: lua_common.hpp:228
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109

Definition at line 230 of file lua_common.hpp.

◆ return_float_attrib

#define return_float_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
lua_pushnumber(L, (accessor)); \
return 1; \
} \
} while(false)

Definition at line 277 of file lua_common.hpp.

◆ return_float_attrib_deprecated

#define return_float_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     return_deprecated_attrib(return_float_attrib, name, accessor, prefix, level, version, msg)

Definition at line 284 of file lua_common.hpp.

◆ return_int_attrib

#define return_int_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
lua_pushinteger(L, (accessor)); \
return 1; \
} \
} while(false)

Definition at line 267 of file lua_common.hpp.

◆ return_int_attrib_deprecated

#define return_int_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     return_deprecated_attrib(return_int_attrib, name, accessor, prefix, level, version, msg)

Definition at line 274 of file lua_common.hpp.

◆ return_string_attrib

#define return_string_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
const std::string& str = (accessor); \
lua_pushlstring(L, str.c_str(), str.length()); \
return 1; \
} \
} while(false)

Definition at line 256 of file lua_common.hpp.

◆ return_string_attrib_deprecated

#define return_string_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     return_deprecated_attrib(return_string_attrib, name, accessor, prefix, level, version, msg)

Definition at line 264 of file lua_common.hpp.

◆ return_tstring_attrib

#define return_tstring_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
luaW_pushtstring(L, (accessor)); \
return 1; \
} \
} while(false)

Definition at line 236 of file lua_common.hpp.

◆ return_tstring_attrib_deprecated

#define return_tstring_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     return_deprecated_attrib(return_tstring_attrib, name, accessor, prefix, level, version, msg)

Definition at line 243 of file lua_common.hpp.

◆ return_vector_string_attrib

#define return_vector_string_attrib (   name,
  accessor 
)
Value:
do { \
if (strcmp(m, (name)) == 0) { \
const std::vector<std::string>& vector = (accessor); \
lua_createtable(L, vector.size(), 0); \
int i = 1; \
for (const std::string& s : vector) { \
lua_pushlstring(L, s.c_str(), s.length()); \
lua_rawseti(L, -2, i); \
++i; \
} \
return 1; \
} \
} while(false)
static map_location::direction s

Definition at line 319 of file lua_common.hpp.

◆ return_vector_string_attrib_deprecated

#define return_vector_string_attrib_deprecated (   name,
  prefix,
  level,
  version,
  msg,
  accessor 
)     return_deprecated_attrib(return_vector_string_attrib, name, accessor, prefix, level, version, msg)

Definition at line 333 of file lua_common.hpp.

Function Documentation

◆ chat_message()

void chat_message ( const std::string &  caption,
const std::string &  msg 
)

◆ luaW_check_locationset()

std::set<map_location> luaW_check_locationset ( lua_State *  L,
int  idx 
)

◆ luaW_checkconfig() [1/2]

config luaW_checkconfig ( lua_State *  L,
int  index 
)

◆ luaW_checkconfig() [2/2]

config luaW_checkconfig ( lua_State *  L,
int  index,
const vconfig *&  vcfg 
)

Like the two-argument version, but if it was a vconfig, also returns a pointer to that vconfig.

Definition at line 935 of file lua_common.cpp.

References utf8::index(), luaW_checkconfig(), p, and vconfigKey.

◆ luaW_checklocation()

map_location luaW_checklocation ( lua_State *  L,
int  index 
)

◆ luaW_checktstring()

t_string luaW_checktstring ( lua_State *  L,
int  index 
)

◆ luaW_checkvariable()

bool luaW_checkvariable ( lua_State *  L,
variable_access_create v,
int  n 
)

◆ luaW_checkvconfig()

vconfig luaW_checkvconfig ( lua_State *  L,
int  index,
bool  allow_missing = false 
)

◆ luaW_filltable()

void luaW_filltable ( lua_State *  L,
const config cfg 
)

Converts a config object to a Lua table.

The destination table should be at the top of the stack on entry. It is still at the top on exit.

Definition at line 654 of file lua_common.cpp.

References config::all_children_view(), config::attribute_range(), luaW_push_namedtuple(), and luaW_pushscalar().

Referenced by luaW_pushconfig(), and luaW_pushvariable().

◆ luaW_getglobal() [1/2]

bool luaW_getglobal ( lua_State *  L,
const std::vector< std::string > &  path 
)

◆ luaW_getglobal() [2/2]

template<typename... T>
bool luaW_getglobal ( lua_State *  L,
T...  path 
)

Pushes the value found by following the variadic names (char *), if the value is not nil.

Returns
true if an element was pushed.

Definition at line 190 of file lua_common.hpp.

References luaW_getglobal(), and game_config::path.

◆ luaW_getmetafield()

bool luaW_getmetafield ( lua_State *  L,
int  idx,
const char *  key 
)

Like luaL_getmetafield, but returns false if key is an empty string or begins with two underscores.

Definition at line 524 of file lua_common.cpp.

References n.

Referenced by impl_animator_get(), impl_floating_label_getmethod(), impl_music_get(), impl_source_get(), impl_track_get(), and impl_unit_attack_get().

◆ luaW_iststring()

bool luaW_iststring ( lua_State *  L,
int  index 
)

Definition at line 643 of file lua_common.cpp.

References utf8::index(), and tstringKey.

Referenced by game_lua_kernel::intf_allow_end_turn(), and lua_stringx::intf_str_format().

◆ luaW_pcall()

bool luaW_pcall ( lua_State *  L,
int  nArgs,
int  nRets,
bool  allow_wml_error = false 
)

◆ luaW_pcall_internal()

int luaW_pcall_internal ( lua_State *  L,
int  nArgs,
int  nRets 
)

◆ luaW_push_locationset()

int luaW_push_locationset ( lua_State *  L,
const std::set< map_location > &  locs 
)

Converts a set of map locations to a Lua table pushed at the top of the stack.

Definition at line 808 of file lua_common.cpp.

References i, loc, and luaW_pushlocation().

Referenced by ai::cfun_ai_get_avoid(), game_lua_kernel::intf_get_locations(), intf_mg_get_locations(), intf_mg_get_tiles_radius(), and intf_parse_shroud_bitmap().

◆ luaW_push_namedtuple()

void luaW_push_namedtuple ( lua_State *  L,
const std::vector< std::string > &  names 
)

Push an empty "named tuple" onto the stack.

A named tuple is an array where each index can also be accessed by name. Once it's pushed, you can set the elements, eg with lua_rawseti.

Definition at line 712 of file lua_common.cpp.

References i, impl_namedtuple_dir(), impl_namedtuple_get(), impl_namedtuple_tostring(), lua_push(), and names.

Referenced by lua_common::impl_vconfig_get(), game_lua_kernel::intf_find_cost_map(), game_lua_kernel::intf_find_reach(), game_lua_kernel::intf_find_vision_range(), intf_named_tuple(), luaW_filltable(), luaW_pushcubeloc(), luaW_pushlocation(), and push_color_palette().

◆ luaW_pushconfig()

void luaW_pushconfig ( lua_State *  L,
const config cfg 
)

◆ luaW_pushlocation()

void luaW_pushlocation ( lua_State *  L,
const map_location loc 
)

◆ luaW_pushscalar()

void luaW_pushscalar ( lua_State *  L,
const config::attribute_value v 
)

Converts an attribute value into a Lua object pushed at the top of the stack.

Definition at line 578 of file lua_common.cpp.

References config_attribute_value::apply_visitor().

Referenced by lua_common::impl_vconfig_get(), lua_common::impl_vconfig_pairs_iter(), luaW_filltable(), and luaW_pushvariable().

◆ luaW_pushtstring()

void luaW_pushtstring ( lua_State *  L,
const t_string v 
)

◆ luaW_pushvariable()

bool luaW_pushvariable ( lua_State *  L,
variable_access_const v 
)

◆ luaW_pushvconfig()

void luaW_pushvconfig ( lua_State *  L,
const vconfig cfg 
)

◆ luaW_tableget()

bool luaW_tableget ( lua_State *  L,
int  index,
const char *  key 
)

◆ luaW_toboolean()

bool luaW_toboolean ( lua_State *  L,
int  n 
)

Definition at line 998 of file lua_common.cpp.

References n.

Referenced by ai::ai_move(), ai::call_lua_filter_fcn(), game_lua_kernel::cfun_builtin_effect(), cfun_exec_candidate_action(), impl_add_animation(), ai::impl_ai_get(), impl_get_dir_suffix(), impl_is_deprecated(), impl_unit_status_set(), intf_add_modification(), intf_advance_unit(), game_lua_kernel::intf_allow_end_turn(), game_lua_kernel::intf_allow_undo(), game_lua_kernel::intf_delay(), game_lua_kernel::intf_find_cost_map(), intf_find_path(), lua_fileops::intf_have_file(), lua_wml::intf_load_wml(), game_lua_kernel::intf_lock_view(), game_lua_kernel::intf_log(), intf_music_add(), intf_on_board(), game_lua_kernel::intf_put_unit(), game_lua_kernel::intf_redraw(), game_lua_kernel::intf_scroll_to_tile(), game_lua_kernel::intf_select_unit(), game_lua_kernel::intf_set_village_owner(), game_lua_kernel::intf_skip_messages(), lua_stringx::intf_str_paren_split(), game_lua_kernel::intf_teleport(), intf_terrainmap_iter(), game_lua_kernel::intf_toggle_fog(), intf_unit_resistance(), game_lua_kernel::intf_zoom(), ai::lua_ai_load::lua_ai_load(), lua_check_impl::lua_check(), lua_check_impl::lua_to_or_default(), luaW_checkvariable(), luaW_get_attributes(), luaW_toscalar(), game_lua_kernel::mouse_button_callback(), read_rules_vector(), game_lua_kernel::run_filter(), game_lua_kernel::run_wml_conditional(), game_lua_kernel::run_wml_event(), lua_gui2::show_menu(), lua_gui2::show_message_box(), ai::lua_object< T >::to_type(), and WIDGET_SETTER().

◆ luaW_toconfig()

bool luaW_toconfig ( lua_State *  L,
int  index,
config cfg 
)

Converts an optional table or vconfig to a config object.

Parameters
Lthe pointer to the lua interpreter.
indexstack position of the table.
cfgthe config to write the data to.
Returns
false if some attributes had not the proper type.
Note
If the table has holes in the integer keys or floating-point keys, some keys will be ignored and the error will go undetected.

Definition at line 849 of file lua_common.cpp.

References config::add_child(), config::clear(), i, utf8::index(), luaW_toscalar(), return_misformed, config_attribute_value::str(), config::valid_attribute(), config::valid_tag(), and vconfigKey.

Referenced by mapgen_lua_kernel::create_scenario(), ai::lua_ai_context::get_arguments(), ai::lua_ai_context::get_persistent_data(), impl_context_accessor(), impl_music_set(), impl_sndsrc_set(), game_lua_kernel::intf_add_event(), game_lua_kernel::intf_add_undo_actions(), game_lua_kernel::intf_fire_event(), game_lua_kernel::intf_log_replay(), intf_modify_ai_old(), lua_wml::intf_wml_valid(), lua_check_impl::lua_to_or_default(), luaW_checkconfig(), luaW_checkvariable(), luaW_tovconfig(), game_lua_kernel::save_game(), lua_gui2::show_message_dialog(), and ai::lua_object< T >::to_type().

◆ luaW_tolocation()

bool luaW_tolocation ( lua_State *  L,
int  index,
map_location loc 
)

Converts an optional table or pair of integers to a map location object.

Parameters
Lthe pointer to the lua interpreter.
indexstack position of the table or first integer.
locthe location to write to.
Returns
false if a map location couldn't be matched.

Definition at line 751 of file lua_common.cpp.

References utf8::index(), loc, map_location::set_wml_x(), map_location::set_wml_y(), and vconfig::unconstructed_vconfig().

Referenced by ai::ai_recall(), ai::ai_recruit(), impl_add_animation(), impl_source_set(), impl_terrainmap_get(), impl_terrainmap_set(), lua_map_location::intf_distance_between(), game_lua_kernel::intf_erase_unit(), game_lua_kernel::intf_fire_event(), lua_map_location::intf_get_adjacent_tiles(), lua_map_location::intf_get_direction(), lua_map_location::intf_get_in_cubic(), lua_map_location::intf_get_relative_dir(), lua_map_location::intf_get_tile_ring(), lua_map_location::intf_get_tiles_in_radius(), game_lua_kernel::intf_get_time_area(), game_lua_kernel::intf_get_time_of_day(), game_lua_kernel::intf_get_unit(), game_lua_kernel::intf_get_units(), game_lua_kernel::intf_match_unit(), game_lua_kernel::intf_put_unit(), lua_map_location::intf_rotate_right_around_center(), lua_map_location::intf_tiles_adjacent(), intf_unit_defense(), intf_unit_jamming_cost(), intf_unit_movement_cost(), intf_unit_vision_cost(), lua_map_location::intf_vector_diff(), lua_map_location::intf_vector_negation(), lua_map_location::intf_vector_sum(), load_fake_units(), lua_check_impl::lua_to_or_default(), luaW_checklocation(), luaW_to_locationset(), and luaW_tofaivariant().

◆ luaW_toscalar()

bool luaW_toscalar ( lua_State *  L,
int  index,
config::attribute_value v 
)

Converts the value at the top of the stack to an attribute value.

Definition at line 583 of file lua_common.cpp.

References utf8::index(), luaW_toboolean(), and tstringKey.

Referenced by luaW_toconfig().

◆ luaW_tostring()

std::string_view luaW_tostring ( lua_State *  L,
int  index 
)

◆ luaW_tostring_or_default()

std::string_view luaW_tostring_or_default ( lua_State *  L,
int  index,
std::string_view  def = std::string_view() 
)

Definition at line 1095 of file lua_common.cpp.

References utf8::index().

Referenced by lua_check_impl::lua_to_or_default().

◆ luaW_totstring()

bool luaW_totstring ( lua_State *  L,
int  index,
t_string str 
)

◆ luaW_tovconfig()

bool luaW_tovconfig ( lua_State *  L,
int  index,
vconfig vcfg 
)

◆ luaW_type_error() [1/2]

int luaW_type_error ( lua_State *  L,
int  narg,
const char *  kpath,
const char *  tname 
)

Definition at line 1198 of file lua_common.cpp.

References wfl::msg().

◆ luaW_type_error() [2/2]

int luaW_type_error ( lua_State *  L,
int  narg,
const char *  tname 
)

◆ operator delete()

void operator delete ( void *  p,
lua_State *  L,
int  nuv 
)

Definition at line 516 of file lua_common.cpp.

◆ operator new()

void* operator new ( std::size_t  sz,
lua_State *  L,
int  nuv = 0 
)

Definition at line 511 of file lua_common.cpp.

◆ push_error_handler()

void push_error_handler ( lua_State *  L)

Definition at line 1112 of file lua_common.cpp.

References executeKey, and luaW_getglobal().

Referenced by lua_kernel_base::lua_kernel_base().