20 #ifndef LUA_COMMON_HPP_INCLUDED
21 #define LUA_COMMON_HPP_INCLUDED
150 template<
typename... T>
163 #define return_tstring_attrib(name, accessor) \
164 if (strcmp(m, name) == 0) { \
165 luaW_pushtstring(L, accessor); \
169 #define return_cstring_attrib(name, accessor) \
170 if (strcmp(m, name) == 0) { \
171 lua_pushstring(L, accessor); \
175 #define return_string_attrib(name, accessor) \
176 return_cstring_attrib(name, (accessor).c_str())
178 #define return_int_attrib(name, accessor) \
179 if (strcmp(m, name) == 0) { \
180 lua_pushinteger(L, accessor); \
184 #define return_float_attrib(name, accessor) \
185 if (strcmp(m, name) == 0) { \
186 lua_pushnumber(L, accessor); \
190 #define return_bool_attrib(name, accessor) \
191 if (strcmp(m, name) == 0) { \
192 lua_pushboolean(L, accessor); \
196 #define return_cfg_attrib(name, accessor) \
197 if (strcmp(m, name) == 0) { \
200 luaW_pushconfig(L, cfg); \
204 #define return_cfgref_attrib(name, accessor) \
205 if (strcmp(m, name) == 0) { \
206 luaW_pushconfig(L, accessor); \
210 #define return_vector_string_attrib(name, accessor) \
211 if (strcmp(m, name) == 0) { \
212 const std::vector<std::string>& vector = accessor; \
213 lua_createtable(L, vector.size(), 0); \
215 for (const std::string& s : vector) { \
216 lua_pushstring(L, s.c_str()); \
217 lua_rawseti(L, -2, i); \
223 #define modify_tstring_attrib(name, accessor) \
224 if (strcmp(m, name) == 0) { \
225 t_string value = luaW_checktstring(L, 3); \
230 #define modify_string_attrib(name, accessor) \
231 if (strcmp(m, name) == 0) { \
232 const char *value = luaL_checkstring(L, 3); \
237 #define modify_int_attrib(name, accessor) \
238 if (strcmp(m, name) == 0) { \
239 int value = luaL_checkinteger(L, 3); \
244 #define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max) \
245 if (strcmp(m, name) == 0) { \
246 int value = luaL_checkinteger(L, 3); \
247 if (value < allowed_min || allowed_max < value) return luaL_argerror(L, 3, "out of bounds"); \
252 #define modify_bool_attrib(name, accessor) \
253 if (strcmp(m, name) == 0) { \
254 bool value = luaW_toboolean(L, 3); \
259 #define modify_vector_string_attrib(name, accessor) \
260 if (strcmp(m, name) == 0) { \
261 std::vector<std::string> vector; \
262 char const* message = "table with unnamed indices holding strings expected"; \
263 if (!lua_istable(L, 3)) return luaL_argerror(L, 3, message); \
264 unsigned length = lua_rawlen(L, 3); \
265 for (unsigned i = 1; i <= length; ++i) { \
266 lua_rawgeti(L, 3, i); \
267 char const* string = lua_tostring(L, 4); \
268 if(!string) return luaL_argerror(L, 2 + i, message); \
269 vector.push_back(string); \
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
std::string register_tstring_metatable(lua_State *L)
Adds the tstring metatable.
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
Extends variable_info with methods that can only be applied if vit != vit_const.
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
int intf_textdomain(lua_State *L)
Creates an interface for gettext.
Definitions for the interface to Wesnoth Markup Language (WML).
Variant for storing WML attributes.
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.
void luaW_filltable(lua_State *L, config const &cfg)
Converts a config object to a Lua table.
bool luaW_totstring(lua_State *L, int index, t_string &str)
Converts a scalar to a translatable string.
GLsizei const char ** path
std::string register_vconfig_metatable(lua_State *L)
Adds the vconfig metatable.
bool luaW_pushvariable(lua_State *L, variable_access_const &v)
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.
Encapsulates the map of the game.
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...
bool luaW_toboolean(lua_State *L, int n)
std::string register_gettext_metatable(lua_State *L)
Adds the gettext metatable.
bool luaW_checkvariable(lua_State *L, variable_access_create &v, int n)
vconfig luaW_checkvconfig(lua_State *L, int index, bool allow_missing=false)
Gets an optional vconfig from either a table or a userdata.
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.
void luaW_pushconfig(lua_State *L, config const &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
void luaW_pushvconfig(lua_State *L, vconfig const &cfg)
Pushes a vconfig on the top of the stack.
void luaW_pushtstring(lua_State *L, t_string const &v)
Pushes a t_string on the top of the stack.
A variable-expanding proxy for the config class.
void luaW_pushlocation(lua_State *L, map_location const &loc)
Converts a map location object to a Lua table pushed at the top of the stack.
A config object defines a single node in a WML file, with access to child nodes.
int intf_tovconfig(lua_State *L)
Creates a vconfig containing the WML table.
GLsizei const GLcharARB ** string
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg)
Gets an optional vconfig from either a table or a userdata.