32 #include <string_view>
67 void*
operator new(std::size_t sz, lua_State *L,
int nuv = 0);
68 void operator delete(
void*
p, lua_State *L,
int nuv);
217 template<
typename... T>
247 bool luaW_pcall(lua_State *L,
int nArgs,
int nRets,
bool allow_wml_error =
false);
254 int luaW_type_error(lua_State *L,
int narg,
const char* kpath,
const char *tname);
260 #define deprecate_attrib(name, prefix, level, version, msg) deprecated_message(prefix "." name, DEP_LEVEL::level, version, msg)
262 #define return_deprecated_attrib(type_macro, name, accessor, prefix, level, version, msg) \
264 deprecate_attrib(name, prefix, level, version, msg), \
268 #define return_tstring_attrib(name, accessor) \
270 if (strcmp(m, (name)) == 0) { \
271 luaW_pushtstring(L, (accessor)); \
275 #define return_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \
276 return_deprecated_attrib(return_tstring_attrib, name, accessor, prefix, level, version, msg)
278 #define return_cstring_attrib(name, accessor) \
280 if (strcmp(m, (name)) == 0) { \
281 lua_pushstring(L, (accessor)); \
285 #define return_cstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \
286 return_deprecated_attrib(return_cstring_attrib, name, accessor, prefix, level, version, msg)
288 #define return_string_attrib(name, accessor) \
290 if (strcmp(m, (name)) == 0) { \
291 const std::string& str = (accessor); \
292 lua_pushlstring(L, str.c_str(), str.length()); \
296 #define return_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
297 return_deprecated_attrib(return_string_attrib, name, accessor, prefix, level, version, msg)
299 #define return_int_attrib(name, accessor) \
301 if (strcmp(m, (name)) == 0) { \
302 lua_pushinteger(L, (accessor)); \
306 #define return_int_attrib_deprecated(name, prefix, level, version, msg, accessor) \
307 return_deprecated_attrib(return_int_attrib, name, accessor, prefix, level, version, msg)
309 #define return_float_attrib(name, accessor) \
311 if (strcmp(m, (name)) == 0) { \
312 lua_pushnumber(L, (accessor)); \
316 #define return_float_attrib_deprecated(name, prefix, level, version, msg, accessor) \
317 return_deprecated_attrib(return_float_attrib, name, accessor, prefix, level, version, msg)
319 #define return_bool_attrib(name, accessor) \
321 if (strcmp(m, (name)) == 0) { \
322 lua_pushboolean(L, (accessor)); \
326 #define return_bool_attrib_deprecated(name, prefix, level, version, msg, accessor) \
327 return_deprecated_attrib(return_bool_attrib, name, accessor, prefix, level, version, msg)
329 #define return_cfg_attrib(name, accessor) \
331 if (strcmp(m, (name)) == 0) { \
334 luaW_pushconfig(L, cfg); \
338 #define return_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor) \
339 return_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
341 #define return_cfgref_attrib(name, accessor) \
343 if (strcmp(m, (name)) == 0) { \
344 luaW_pushconfig(L, (accessor)); \
348 #define return_cfgref_attrib_deprecated(name, prefix, level, version, msg, accessor) \
349 return_deprecated_attrib(return_cfgref_attrib, name, accessor, prefix, level, version, msg)
351 #define return_vector_string_attrib(name, accessor) \
353 if (strcmp(m, (name)) == 0) { \
354 const std::vector<std::string>& vector = (accessor); \
355 lua_createtable(L, vector.size(), 0); \
357 for (const std::string& s : vector) { \
358 lua_pushlstring(L, s.c_str(), s.length()); \
359 lua_rawseti(L, -2, i); \
365 #define return_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
366 return_deprecated_attrib(return_vector_string_attrib, name, accessor, prefix, level, version, msg)
368 #define modify_tstring_attrib(name, accessor) \
370 if (strcmp(m, (name)) == 0) { \
371 t_string value = luaW_checktstring(L, 3); \
376 #define modify_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \
377 modify_tstring_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
379 #define modify_string_attrib(name, accessor) \
381 if (strcmp(m, (name)) == 0) { \
382 const char *value = luaL_checkstring(L, 3); \
387 #define modify_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
388 modify_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
390 #define modify_int_attrib(name, accessor) \
392 if (strcmp(m, (name)) == 0) { \
393 int value = static_cast<int>(luaL_checknumber(L, 3)); \
398 #define modify_int_attrib_deprecated(name, prefix, level, version, msg, accessor) \
399 modify_int_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
401 #define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max) \
403 if (strcmp(m, (name)) == 0) { \
404 int value = static_cast<int>(luaL_checknumber(L, 3)); \
405 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \
410 #define modify_int_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max) \
411 modify_int_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)
413 #define modify_float_attrib(name, accessor) \
415 if (strcmp(m, (name)) == 0) { \
416 lua_Number value = luaL_checknumber(L, 3); \
421 #define modify_float_attrib_deprecated(name, prefix, level, version, msg, accessor) \
422 modify_float_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
424 #define modify_float_attrib_check_range(name, accessor, allowed_min, allowed_max) \
426 if (strcmp(m, (name)) == 0) { \
427 lua_Number value = luaL_checknumber(L, 3); \
428 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \
433 #define modify_float_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max) \
434 modify_float_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)
436 #define modify_bool_attrib(name, accessor) \
438 if (strcmp(m, (name)) == 0) { \
439 bool value = luaW_toboolean(L, 3); \
444 #define modify_bool_attrib_deprecated(name, prefix, level, version, msg, accessor) \
445 modify_bool_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
447 #define modify_cfg_attrib(name, accessor) \
449 if (strcmp(m, (name)) == 0) { \
450 const config& cfg = luaW_checkconfig(L, 3); \
455 #define modify_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor) \
456 modify_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
458 #define modify_vector_string_attrib(name, accessor) \
460 if (strcmp(m, (name)) == 0) { \
461 std::vector<std::string> value; \
462 char const* message = "table with unnamed indices holding strings expected"; \
463 if (!lua_istable(L, 3)) return luaL_argerror(L, 3, message); \
464 unsigned length = lua_rawlen(L, 3); \
465 for (unsigned i = 1; i <= length; ++i) { \
466 lua_rawgeti(L, 3, i); \
467 char const* string = lua_tostring(L, 4); \
468 if(!string) return luaL_argerror(L, 2 + i, message); \
469 value.push_back(string); \
476 #define modify_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
477 modify_vector_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
std::vector< std::string > names
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
Shallow wrapper around lua_geti which pops the top variable from the Lua stack when destroyed.
scoped_lua_argument(lua_State *L, int arg_index)
scoped_lua_argument(const scoped_lua_argument &)=delete
scoped_lua_argument & operator=(const scoped_lua_argument &)=delete
Additional functionality for a non-const variable_info.
Information on a WML variable.
A variable-expanding proxy for the config class.
Definitions for the interface to Wesnoth Markup Language (WML).
void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
int luaW_pcall_internal(lua_State *L, int nArgs, int nRets)
void luaW_filltable(lua_State *L, const config &cfg)
Converts a config object to a Lua table.
void chat_message(const std::string &caption, const std::string &msg)
Displays a message in the chat window.
void push_error_handler(lua_State *L)
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_iststring(lua_State *L, int index)
void luaW_push_namedtuple(lua_State *L, const std::vector< std::string > &names)
Push an empty "named tuple" onto the stack.
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
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.
void luaW_pushtstring(lua_State *L, const t_string &v)
Pushes a t_string on the top of the stack.
bool luaW_pushvariable(lua_State *L, variable_access_const &v)
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg)
Gets an optional vconfig from either a table or a userdata.
void luaW_pushvconfig(lua_State *L, const vconfig &cfg)
Pushes a vconfig on the top of the stack.
bool luaW_toboolean(lua_State *L, int n)
int luaW_type_error(lua_State *L, int narg, const char *tname)
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.
std::string_view luaW_tostring(lua_State *L, int index)
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.
std::ostream & operator<<(std::ostream &os, const luaW_PrintStack &)
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_totstring(lua_State *L, int index, t_string &str)
Converts a scalar to a translatable string.
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.
std::vector< std::string > luaW_to_namedtuple(lua_State *L, int idx)
Get the keys of a "named tuple" from the stack.
bool luaW_tableget(lua_State *L, int index, const char *key)
bool luaW_checkvariable(lua_State *L, variable_access_create &v, int n)
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
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.
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.
std::string_view luaW_tostring_or_default(lua_State *L, int index, std::string_view def=std::string_view())
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
luaW_PrintStack luaW_debugstack(lua_State *L)
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.
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
int intf_textdomain(lua_State *L)
Creates an interface for gettext.
std::string register_gettext_metatable(lua_State *L)
Adds the gettext metatable.
std::string register_vconfig_metatable(lua_State *L)
Adds the vconfig metatable.
std::string register_tstring_metatable(lua_State *L)
Adds the tstring metatable.
int intf_tovconfig(lua_State *L)
Creates a vconfig containing the WML table.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Encapsulates the map of the game.
static map_location::direction n