51 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
52 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua)
53 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
137 t->t_string::~t_string();
190 if (pos >= len)
return 0;
191 std::advance(i, pos);
202 if (strcmp(m,
"__literal") == 0) {
206 if (strcmp(m,
"__parsed") == 0) {
211 bool shallow_literal = strcmp(m,
"__shallow_literal") == 0;
212 if (shallow_literal || strcmp(m,
"__shallow_parsed") == 0)
224 if (shallow_literal) {
226 i_end.disable_insertion();
228 for (
int j = 1; i != i_end; ++
i, ++j)
274 if (range.first == range.second) {
290 const_attr_itors* cai =
static_cast<const_attr_itors*
>(
p);
291 cai->~const_attr_itors();
320 vconfig_child_range&
range = *
static_cast<vconfig_child_range*
>(
p);
321 if (range.first == range.second) {
324 std::pair<std::string, vconfig>
value = *range.first++;
340 vconfig_child_range* vcr =
static_cast<vconfig_child_range*
>(
p);
341 vcr->~vconfig_child_range();
380 static luaL_Reg const callbacks[] = {
389 return "Adding gettext metatable...\n";
399 static luaL_Reg const callbacks[] = {
413 return "Adding tstring metatable...\n";
423 static luaL_Reg const callbacks[] = {
451 return "Adding vconfig metatable...\n";
470 struct luaW_pushscalar_visitor : boost::static_visitor<>
473 luaW_pushscalar_visitor(
lua_State *
l): L(l) {}
475 void operator()(boost::blank
const &)
const
477 void operator()(
bool b)
const
479 void operator()(
int i)
const
481 void operator()(
unsigned long long ull)
const
483 void operator()(
double d)
const
487 void operator()(
t_string const &s)
const
621 int x_was_num = 0, y_was_num = 0;
627 if (!x_was_num || !y_was_num) {
639 if (x_was_num && y_was_num) {
672 #define return_misformed() \
673 do { lua_settop(L, initial_top); return false; } while (0)
691 cfg = ptr->get_parsed_config();
705 for (
int i = 1, i_end =
lua_rawlen(L, index);
i <= i_end; ++
i)
726 std::ostringstream str;
731 if (
i > 1) str <<
',';
746 #undef return_misformed
765 if (!ok)
return false;
850 switch (variabletype) {
865 goto default_explicit;
bool luaW_checkvariable(lua_State *L, variable_access_create &v, int n)
LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
static int impl_vconfig_collect(lua_State *L)
Destroys a vconfig object before it is collected (__gc metamethod).
void luaW_pushvconfig(lua_State *L, vconfig const &cfg)
Pushes a vconfig on the top of the stack.
static const char * vconfigKey
#define lua_isnoneornil(L, n)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
LUALIB_API void * luaL_checkudata(lua_State *L, int ud, const char *tname)
variable_info_detail::maybe_const< vit, config::attribute_value >::type & as_scalar() const
might throw invalid_variablename_exception NOTE: If vit == vit_const, then the lifime of the returned...
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
#define lua_pushcfunction(L, f)
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.
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
std::string register_tstring_metatable(lua_State *L)
Adds the tstring metatable.
static lg::log_domain log_scripting_lua("scripting/lua")
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg)
Gets an optional vconfig from either a table or a userdata.
LUA_API void lua_settop(lua_State *L, int idx)
std::pair< const_attribute_iterator, const_attribute_iterator > const_attr_itors
LUA_API int lua_type(lua_State *L, int idx)
bool exists_as_container() const
might throw invalid_variablename_exception
LUA_API void lua_pushboolean(lua_State *L, int b)
vconfig get_child() const
config get_parsed_config() const
static int impl_gettext(lua_State *L)
Creates a t_string object (__call metamethod).
int compare(const std::string &s1, const std::string &s2)
all_children_iterator ordered_end() const
Extends variable_info with methods that can only be applied if vit != vit_const.
static int impl_vconfig_get(lua_State *L)
Gets the parsed field of a vconfig object (_index metamethod).
LUA_API int lua_gettop(lua_State *L)
bool luaW_pushvariable(lua_State *L, variable_access_const &v)
attribute_map::value_type attribute
int intf_textdomain(lua_State *L)
Creates an interface for gettext.
#define lua_tointeger(L, i)
~vconfig()
Default destructor, but defined here for possibly faster compiles (templates sometimes can be rough o...
static int impl_vconfig_ipairs(lua_State *L)
Construct an iterator to iterate through the subtags of a vconfig.
#define lua_tonumber(L, i)
V::result_type apply_visitor(const V &visitor) const
Applies a visitor to the underlying variant.
LUA_API int lua_isuserdata(lua_State *L, int idx)
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
LUALIB_API void luaL_setmetatable(lua_State *L, const char *tname)
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
Definitions for the interface to Wesnoth Markup Language (WML).
LUA_API int lua_absindex(lua_State *L, int idx)
LUA_API void * lua_newuserdata(lua_State *L, size_t size)
Variant for storing WML attributes.
unit * luaW_tounit(lua_State *L, int index, bool only_on_map)
Converts a Lua value to a unit pointer.
#define return_misformed()
GLdouble GLdouble GLdouble b
#define lua_upvalueindex(i)
GLsizei const char ** path
std::string register_vconfig_metatable(lua_State *L)
Adds the vconfig metatable.
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...
LUA_API int lua_isstring(lua_State *L, int idx)
bool luaW_toboolean(lua_State *L, int n)
LUA_API int lua_rawequal(lua_State *L, int index1, int index2)
static int impl_tstring_concat(lua_State *L)
Appends a scalar to a t_string object (__concat metamethod).
static const char * gettextKey
LUA_API int lua_toboolean(lua_State *L, int idx)
GLsizei const GLfloat * value
all_children_itors all_children_range() const
In-order iteration over all children.
void luaW_pushtstring(lua_State *L, t_string const &v)
Pushes a t_string on the top of the stack.
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
#define lua_pushglobaltable(L)
GLboolean GLboolean GLboolean GLboolean a
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
config & add_child(const std::string &key)
LUA_API int lua_getmetatable(lua_State *L, int objindex)
LUA_API int lua_setmetatable(lua_State *L, int objindex)
const t_string_base & get() const
LUA_API void lua_remove(lua_State *L, int idx)
const char * c_str() const
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
static const char * vconfigpairsKey
LUA_API lua_Number lua_tonumberx(lua_State *L, int idx, int *isnum)
static int impl_vconfig_pairs_collect(lua_State *L)
Destroy a vconfig pairs iterator.
static int impl_tstring_tostring(lua_State *L)
Converts a t_string object to a string (__tostring metamethod); that is, performs a translation...
LUA_API void lua_pushnil(lua_State *L)
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)
static int impl_vconfig_pairs(lua_State *L)
Construct an iterator to iterate through the attributes of a vconfig.
Encapsulates the map of the game.
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
bool luaW_totstring(lua_State *L, int index, t_string &str)
Converts a scalar to a translatable string.
static int impl_vconfig_size(lua_State *L)
Returns the number of a child of a vconfig object.
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
LUA_API void * lua_touserdata(lua_State *L, int idx)
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.
variable_info_detail::maybe_const< vit, config >::type & as_container() const
might throw invalid_variablename_exception
static int impl_tstring_eq(lua_State *L)
static int impl_tstring_lt(lua_State *L)
LUA_API void lua_rawset(lua_State *L, int idx)
std::string register_gettext_metatable(lua_State *L)
Adds the gettext metatable.
config::attribute_value expand(const std::string &) const
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
static int impl_tstring_le(lua_State *L)
const config & get_config() const
const_attr_itors attribute_range() const
static int impl_vconfig_ipairs_collect(lua_State *L)
Destroy a vconfig ipairs iterator.
Information on a WML variable.
#define lua_tostring(L, i)
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
void luaW_filltable(lua_State *L, config const &cfg)
Converts a config object to a Lua table.
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API int lua_isnumber(lua_State *L, int idx)
static vconfig unconstructed_vconfig()
This is just a wrapper for the default constructor; it exists for historical reasons and to make it c...
std::pair< vconfig::all_children_iterator, vconfig::all_children_iterator > vconfig_child_range
LUA_API size_t lua_rawlen(lua_State *L, int idx)
#define LUA_REGISTRYINDEX
static int impl_vconfig_ipairs_iter(lua_State *L)
Iterate through the subtags of a vconfig.
#define lua_istable(L, n)
void luaW_pushconfig(lua_State *L, config const &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
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.
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.
A variable-expanding proxy for the config class.
Standard logging facilities (interface).
std::string get_error_message() const
LUA_API int lua_checkstack(lua_State *L, int size)
vconfig luaW_checkvconfig(lua_State *L, int index, bool allow_missing)
Gets an optional vconfig from either a table or a userdata.
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
bool exists_as_attribute() const
might throw invalid_variablename_exception
A config object defines a single node in a WML file, with access to child nodes.
static int impl_tstring_collect(lua_State *L)
Destroys a t_string object before it is collected (__gc metamethod).
static void tstring_concat_aux(lua_State *L, t_string &dst, int src)
Converts a Lua value at position src and appends it to dst.
int intf_tovconfig(lua_State *L)
Creates a vconfig containing the WML table.
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
static int impl_vconfig_pairs_iter(lua_State *L)
Iterate through the attributes of a vconfig.
LUALIB_API int luaL_typerror(lua_State *L, int narg, const char *tname)
LUA_API void lua_rawget(lua_State *L, int idx)
GLsizei const GLcharARB ** string
std::string get_key() const
bool has_attribute(const std::string &key) const
< Synonym for operator[]
all_children_iterator ordered_begin() const
In-order iteration over all children.
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API int lua_next(lua_State *L, int idx)
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
LUA_API const char * lua_typename(lua_State *L, int t)
static const char * vconfigipairsKey
#define luaL_checkstring(L, n)