31 #include <string_view> 44 void*
operator new(std::size_t sz,
lua_State *L);
171 template<
typename... T>
210 #define return_tstring_attrib(name, accessor) \ 212 if (strcmp(m, (name)) == 0) { \ 213 luaW_pushtstring(L, (accessor)); \ 218 #define return_cstring_attrib(name, accessor) \ 220 if (strcmp(m, (name)) == 0) { \ 221 lua_pushstring(L, (accessor)); \ 226 #define return_string_attrib(name, accessor) \ 228 if (strcmp(m, (name)) == 0) { \ 229 const std::string& str = (accessor); \ 230 lua_pushlstring(L, str.c_str(), str.length()); \ 235 #define return_int_attrib(name, accessor) \ 237 if (strcmp(m, (name)) == 0) { \ 238 lua_pushinteger(L, (accessor)); \ 243 #define return_float_attrib(name, accessor) \ 245 if (strcmp(m, (name)) == 0) { \ 246 lua_pushnumber(L, (accessor)); \ 251 #define return_bool_attrib(name, accessor) \ 253 if (strcmp(m, (name)) == 0) { \ 254 lua_pushboolean(L, (accessor)); \ 259 #define return_cfg_attrib(name, accessor) \ 261 if (strcmp(m, (name)) == 0) { \ 264 luaW_pushconfig(L, cfg); \ 269 #define return_cfgref_attrib(name, accessor) \ 271 if (strcmp(m, (name)) == 0) { \ 272 luaW_pushconfig(L, (accessor)); \ 277 #define return_vector_string_attrib(name, accessor) \ 279 if (strcmp(m, (name)) == 0) { \ 280 const std::vector<std::string>& vector = (accessor); \ 281 lua_createtable(L, vector.size(), 0); \ 283 for (const std::string& s : vector) { \ 284 lua_pushlstring(L, s.c_str(), s.length()); \ 285 lua_rawseti(L, -2, i); \ 292 #define modify_tstring_attrib(name, accessor) \ 294 if (strcmp(m, (name)) == 0) { \ 295 t_string value = luaW_checktstring(L, 3); \ 301 #define modify_string_attrib(name, accessor) \ 303 if (strcmp(m, (name)) == 0) { \ 304 const char *value = luaL_checkstring(L, 3); \ 310 #define modify_int_attrib(name, accessor) \ 312 if (strcmp(m, (name)) == 0) { \ 313 int value = static_cast<int>(luaL_checknumber(L, 3)); \ 319 #define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max) \ 321 if (strcmp(m, (name)) == 0) { \ 322 int value = static_cast<int>(luaL_checknumber(L, 3)); \ 323 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \ 329 #define modify_float_attrib(name, accessor) \ 331 if (strcmp(m, (name)) == 0) { \ 332 lua_Number value = luaL_checknumber(L, 3); \ 338 #define modify_float_attrib_check_range(name, accessor, allowed_min, allowed_max) \ 340 if (strcmp(m, (name)) == 0) { \ 341 lua_Number value = luaL_checknumber(L, 3); \ 342 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \ 348 #define modify_bool_attrib(name, accessor) \ 350 if (strcmp(m, (name)) == 0) { \ 351 bool value = luaW_toboolean(L, 3); \ 357 #define modify_cfg_attrib(name, accessor) \ 359 if (strcmp(m, (name)) == 0) { \ 360 const config& cfg = luaW_checkconfig(L, 3); \ 366 #define modify_vector_string_attrib(name, accessor) \ 368 if (strcmp(m, (name)) == 0) { \ 369 std::vector<std::string> value; \ 370 char const* message = "table with unnamed indices holding strings expected"; \ 371 if (!lua_istable(L, 3)) return luaL_argerror(L, 3, message); \ 372 unsigned length = lua_rawlen(L, 3); \ 373 for (unsigned i = 1; i <= length; ++i) { \ 374 lua_rawgeti(L, 3, i); \ 375 char const* string = lua_tostring(L, 4); \ 376 if(!string) return luaL_argerror(L, 2 + i, message); \ 377 value.push_back(string); \ void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
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.
Variant for storing WML attributes.
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...
bool luaW_iststring(lua_State *L, int index)
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.
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.
bool luaW_tableget(lua_State *L, int index, const char *key)
void luaW_pushtstring(lua_State *L, const t_string &v)
Pushes a t_string on the top of the stack.
void push_error_handler(lua_State *L)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Additional functionality for a non-const variable_info.
Definitions for the interface to Wesnoth Markup Language (WML).
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.
bool luaW_totstring(lua_State *L, int index, t_string &str)
Converts a scalar to a translatable string.
std::string register_vconfig_metatable(lua_State *L)
Adds the vconfig metatable.
bool luaW_pushvariable(lua_State *L, variable_access_const &v)
int luaW_pcall_internal(lua_State *L, int nArgs, int nRets)
std::string_view luaW_tostring_or_default(lua_State *L, int index, std::string_view def=std::string_view())
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)
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.
vconfig luaW_checkvconfig(lua_State *L, int index, bool allow_missing=false)
Gets an optional vconfig from either a table or a userdata.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
std::string_view luaW_tostring(lua_State *L, int index)
void luaW_pushvconfig(lua_State *L, const vconfig &cfg)
Pushes a vconfig on 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.
int luaW_type_error(lua_State *L, int narg, const char *tname)
void chat_message(const std::string &caption, const std::string &msg)
Displays a message in the chat window.
Information on a WML variable.
void luaW_filltable(lua_State *L, const config &cfg)
Converts a config object to a Lua table.
A variable-expanding proxy for the config class.
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.
static map_location::DIRECTION n
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
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.
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg)
Gets an optional vconfig from either a table or a userdata.