32 #include <string_view> 45 void*
operator new(std::size_t sz, lua_State *L,
int nuv = 0);
46 void operator delete(
void*
p, lua_State *L,
int nuv);
189 template<
typename... T>
219 bool luaW_pcall(lua_State *L,
int nArgs,
int nRets,
bool allow_wml_error =
false);
226 int luaW_type_error(lua_State *L,
int narg,
const char* kpath,
const char *tname);
228 #define deprecate_attrib(name, prefix, level, version, msg) deprecated_message(prefix "." name, DEP_LEVEL::level, version, msg) 230 #define return_deprecated_attrib(type_macro, name, accessor, prefix, level, version, msg) \ 232 deprecate_attrib(name, prefix, level, version, msg), \ 236 #define return_tstring_attrib(name, accessor) \ 238 if (strcmp(m, (name)) == 0) { \ 239 luaW_pushtstring(L, (accessor)); \ 243 #define return_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 244 return_deprecated_attrib(return_tstring_attrib, name, accessor, prefix, level, version, msg) 246 #define return_cstring_attrib(name, accessor) \ 248 if (strcmp(m, (name)) == 0) { \ 249 lua_pushstring(L, (accessor)); \ 253 #define return_cstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 254 return_deprecated_attrib(return_cstring_attrib, name, accessor, prefix, level, version, msg) 256 #define return_string_attrib(name, accessor) \ 258 if (strcmp(m, (name)) == 0) { \ 259 const std::string& str = (accessor); \ 260 lua_pushlstring(L, str.c_str(), str.length()); \ 264 #define return_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 265 return_deprecated_attrib(return_string_attrib, name, accessor, prefix, level, version, msg) 267 #define return_int_attrib(name, accessor) \ 269 if (strcmp(m, (name)) == 0) { \ 270 lua_pushinteger(L, (accessor)); \ 274 #define return_int_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 275 return_deprecated_attrib(return_int_attrib, name, accessor, prefix, level, version, msg) 277 #define return_float_attrib(name, accessor) \ 279 if (strcmp(m, (name)) == 0) { \ 280 lua_pushnumber(L, (accessor)); \ 284 #define return_float_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 285 return_deprecated_attrib(return_float_attrib, name, accessor, prefix, level, version, msg) 287 #define return_bool_attrib(name, accessor) \ 289 if (strcmp(m, (name)) == 0) { \ 290 lua_pushboolean(L, (accessor)); \ 294 #define return_bool_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 295 return_deprecated_attrib(return_bool_attrib, name, accessor, prefix, level, version, msg) 297 #define return_cfg_attrib(name, accessor) \ 299 if (strcmp(m, (name)) == 0) { \ 302 luaW_pushconfig(L, cfg); \ 306 #define return_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 307 return_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor) 309 #define return_cfgref_attrib(name, accessor) \ 311 if (strcmp(m, (name)) == 0) { \ 312 luaW_pushconfig(L, (accessor)); \ 316 #define return_cfgref_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 317 return_deprecated_attrib(return_cfgref_attrib, name, accessor, prefix, level, version, msg) 319 #define return_vector_string_attrib(name, accessor) \ 321 if (strcmp(m, (name)) == 0) { \ 322 const std::vector<std::string>& vector = (accessor); \ 323 lua_createtable(L, vector.size(), 0); \ 325 for (const std::string& s : vector) { \ 326 lua_pushlstring(L, s.c_str(), s.length()); \ 327 lua_rawseti(L, -2, i); \ 333 #define return_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 334 return_deprecated_attrib(return_vector_string_attrib, name, accessor, prefix, level, version, msg) 336 #define modify_tstring_attrib(name, accessor) \ 338 if (strcmp(m, (name)) == 0) { \ 339 t_string value = luaW_checktstring(L, 3); \ 344 #define modify_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 345 modify_tstring_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor) 347 #define modify_string_attrib(name, accessor) \ 349 if (strcmp(m, (name)) == 0) { \ 350 const char *value = luaL_checkstring(L, 3); \ 355 #define modify_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 356 modify_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor) 358 #define modify_int_attrib(name, accessor) \ 360 if (strcmp(m, (name)) == 0) { \ 361 int value = static_cast<int>(luaL_checknumber(L, 3)); \ 366 #define modify_int_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 367 modify_int_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor) 369 #define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max) \ 371 if (strcmp(m, (name)) == 0) { \ 372 int value = static_cast<int>(luaL_checknumber(L, 3)); \ 373 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \ 378 #define modify_int_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max) \ 379 modify_int_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max) 381 #define modify_float_attrib(name, accessor) \ 383 if (strcmp(m, (name)) == 0) { \ 384 lua_Number value = luaL_checknumber(L, 3); \ 389 #define modify_float_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 390 modify_float_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor) 392 #define modify_float_attrib_check_range(name, accessor, allowed_min, allowed_max) \ 394 if (strcmp(m, (name)) == 0) { \ 395 lua_Number value = luaL_checknumber(L, 3); \ 396 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \ 401 #define modify_float_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max) \ 402 modify_float_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max) 404 #define modify_bool_attrib(name, accessor) \ 406 if (strcmp(m, (name)) == 0) { \ 407 bool value = luaW_toboolean(L, 3); \ 412 #define modify_bool_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 413 modify_bool_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor) 415 #define modify_cfg_attrib(name, accessor) \ 417 if (strcmp(m, (name)) == 0) { \ 418 const config& cfg = luaW_checkconfig(L, 3); \ 423 #define modify_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 424 modify_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor) 426 #define modify_vector_string_attrib(name, accessor) \ 428 if (strcmp(m, (name)) == 0) { \ 429 std::vector<std::string> value; \ 430 char const* message = "table with unnamed indices holding strings expected"; \ 431 if (!lua_istable(L, 3)) return luaL_argerror(L, 3, message); \ 432 unsigned length = lua_rawlen(L, 3); \ 433 for (unsigned i = 1; i <= length; ++i) { \ 434 lua_rawgeti(L, 3, i); \ 435 char const* string = lua_tostring(L, 4); \ 436 if(!string) return luaL_argerror(L, 2 + i, message); \ 437 value.push_back(string); \ 444 #define modify_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \ 445 modify_vector_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor) 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())
void luaW_push_namedtuple(lua_State *L, const std::vector< std::string > &names)
Push an empty "named tuple" onto 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)
std::vector< std::string > names
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)
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.
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.
std::set< map_location > luaW_check_locationset(lua_State *L, int idx)
Converts a table of integer pairs to a set of map location objects.
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.