The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Namespaces | Macros | Typedefs | Functions | Variables
lua_common.cpp File Reference

Contains code common to the application and game lua kernels which cannot or should not go into the lua kernel base files. More...

#include "scripting/lua_common.hpp"
#include "global.hpp"
#include "config.hpp"
#include "scripting/lua_api.hpp"
#include "scripting/lua_types.hpp"
#include "tstring.hpp"
#include "variable.hpp"
#include "log.hpp"
#include "gettext.hpp"
#include <cstring>
#include <iterator>
#include <new>
#include <string>
#include "lua/lauxlib.h"
#include "lua/lua.h"
Include dependency graph for lua_common.cpp:

Go to the source code of this file.

Namespaces

 lua_common
 

Macros

#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)
 
#define return_misformed()   do { lua_settop(L, initial_top); return false; } while (0)
 

Typedefs

typedef std::pair
< vconfig::all_children_iterator,
vconfig::all_children_iterator
lua_common::vconfig_child_range
 

Functions

static int lua_common::impl_gettext (lua_State *L)
 Creates a t_string object (__call metamethod). More...
 
int lua_common::intf_textdomain (lua_State *L)
 Creates an interface for gettext. More...
 
static void lua_common::tstring_concat_aux (lua_State *L, t_string &dst, int src)
 Converts a Lua value at position src and appends it to dst. More...
 
static int lua_common::impl_tstring_concat (lua_State *L)
 Appends a scalar to a t_string object (__concat metamethod). More...
 
static int lua_common::impl_tstring_collect (lua_State *L)
 Destroys a t_string object before it is collected (__gc metamethod). More...
 
static int lua_common::impl_tstring_lt (lua_State *L)
 
static int lua_common::impl_tstring_le (lua_State *L)
 
static int lua_common::impl_tstring_eq (lua_State *L)
 
static int lua_common::impl_tstring_tostring (lua_State *L)
 Converts a t_string object to a string (__tostring metamethod); that is, performs a translation. More...
 
static int lua_common::impl_vconfig_get (lua_State *L)
 Gets the parsed field of a vconfig object (_index metamethod). More...
 
static int lua_common::impl_vconfig_size (lua_State *L)
 Returns the number of a child of a vconfig object. More...
 
static int lua_common::impl_vconfig_collect (lua_State *L)
 Destroys a vconfig object before it is collected (__gc metamethod). More...
 
static int lua_common::impl_vconfig_pairs_iter (lua_State *L)
 Iterate through the attributes of a vconfig. More...
 
static int lua_common::impl_vconfig_pairs_collect (lua_State *L)
 Destroy a vconfig pairs iterator. More...
 
static int lua_common::impl_vconfig_pairs (lua_State *L)
 Construct an iterator to iterate through the attributes of a vconfig. More...
 
static int lua_common::impl_vconfig_ipairs_iter (lua_State *L)
 Iterate through the subtags of a vconfig. More...
 
static int lua_common::impl_vconfig_ipairs_collect (lua_State *L)
 Destroy a vconfig ipairs iterator. More...
 
static int lua_common::impl_vconfig_ipairs (lua_State *L)
 Construct an iterator to iterate through the subtags of a vconfig. 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 luaW_pushvconfig (lua_State *L, vconfig const &cfg)
 Pushes a vconfig on the top of the stack. More...
 
void luaW_pushtstring (lua_State *L, t_string const &v)
 Pushes a t_string on the top of the stack. More...
 
void luaW_pushscalar (lua_State *L, config::attribute_value const &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_hasmetatable (lua_State *L, int index, luatypekey key)
 Returns true if the metatable of the object is the one found in the registry. 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...
 
void luaW_filltable (lua_State *L, config const &cfg)
 Converts a config object to a Lua table. More...
 
void luaW_pushlocation (lua_State *L, const map_location &ml)
 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...
 
void luaW_pushconfig (lua_State *L, config const &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)
 Gets an optional vconfig from either a table or a userdata. 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...
 
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)
 

Variables

static const char * gettextKey = "gettext"
 
static const char * vconfigKey = "vconfig"
 
static const char * vconfigpairsKey = "vconfig pairs"
 
static const char * vconfigipairsKey = "vconfig ipairs"
 
const char * tstringKey = "translatable string"
 
static lg::log_domain log_scripting_lua ("scripting/lua")
 

Detailed Description

Contains code common to the application and game lua kernels which cannot or should not go into the lua kernel base files.

Currently contains implementation functions related to vconfig and gettext, also some macros to assist in writing C lua callbacks.

Definition in file lua_common.cpp.

Macro Definition Documentation

#define ERR_LUA   LOG_STREAM(err, log_scripting_lua)

Definition at line 53 of file lua_common.cpp.

#define LOG_LUA   LOG_STREAM(info, log_scripting_lua)

Definition at line 51 of file lua_common.cpp.

#define return_misformed ( )    do { lua_settop(L, initial_top); return false; } while (0)

Definition at line 672 of file lua_common.cpp.

Referenced by luaW_toconfig().

#define WRN_LUA   LOG_STREAM(warn, log_scripting_lua)

Definition at line 52 of file lua_common.cpp.

Referenced by luaW_checkvariable(), and luaW_pushvariable().

Function Documentation

config luaW_checkconfig ( lua_State L,
int  index 
)
map_location luaW_checklocation ( lua_State L,
int  index 
)
t_string luaW_checktstring ( lua_State L,
int  index 
)
bool luaW_checkvariable ( lua_State L,
variable_access_create v,
int  n 
)
vconfig luaW_checkvconfig ( lua_State L,
int  index,
bool  allow_missing = false 
)
void luaW_filltable ( lua_State L,
config const &  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 570 of file lua_common.cpp.

References config::all_children_range(), config::attribute_range(), lua_checkstack(), lua_createtable(), LUA_MINSTACK, lua_newtable, lua_pushstring(), lua_rawseti(), lua_setfield(), luaW_filltable(), and luaW_pushscalar().

Referenced by luaW_filltable(), luaW_pushconfig(), and luaW_pushvariable().

bool luaW_getglobal ( lua_State L,
const std::vector< std::string > &  path 
)
bool luaW_hasmetatable ( lua_State L,
int  index,
luatypekey  key 
)
void luaW_pushconfig ( lua_State L,
config const &  cfg 
)
void luaW_pushlocation ( lua_State L,
const map_location ml 
)
void luaW_pushscalar ( lua_State L,
config::attribute_value const &  v 
)

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

Definition at line 492 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().

void luaW_pushtstring ( lua_State L,
t_string const &  v 
)
bool luaW_pushvariable ( lua_State L,
variable_access_const v 
)
void luaW_pushvconfig ( lua_State L,
vconfig const &  cfg 
)
bool luaW_toboolean ( lua_State L,
int  n 
)
bool luaW_toconfig ( lua_State L,
int  index,
config cfg 
)
bool luaW_tolocation ( lua_State L,
int  index,
map_location loc 
)
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 497 of file lua_common.cpp.

References LUA_TBOOLEAN, LUA_TNUMBER, lua_tonumber, lua_tostring, LUA_TSTRING, LUA_TUSERDATA, lua_type(), luaL_testudata(), luaW_toboolean(), and tstringKey.

Referenced by luaW_toconfig().

bool luaW_totstring ( lua_State L,
int  index,
t_string str 
)
bool luaW_tovconfig ( lua_State L,
int  index,
vconfig vcfg 
)

Gets an optional vconfig from either a table or a userdata.

Returns
false in case of failure.

Definition at line 757 of file lua_common.cpp.

References LUA_TNIL, LUA_TNONE, LUA_TTABLE, LUA_TUSERDATA, lua_type(), luaL_testudata(), luaW_toconfig(), and vconfigKey.

Referenced by game_lua_kernel::intf_find_cost_map(), luaW_checkvconfig(), luaW_tofaivariant(), luaW_tolocation(), and ai::lua_object< T >::to_type().

Variable Documentation

const char* gettextKey = "gettext"
static
lg::log_domain log_scripting_lua("scripting/lua")
static
const char* tstringKey = "translatable string"
const char* vconfigipairsKey = "vconfig ipairs"
static
const char* vconfigKey = "vconfig"
static
const char* vconfigpairsKey = "vconfig pairs"
static