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);
95 void push(lua_State *L)
const;
105 static std::string
build_key(
const std::vector<std::string>&
names);
107 static constexpr std::string_view
base_name_ =
"named tuple";
253 template<
typename... T>
283 bool luaW_pcall(lua_State *L,
int nArgs,
int nRets,
bool allow_wml_error =
false);
290 int luaW_type_error(lua_State *L,
int narg,
const char* kpath,
const char *tname);
296 #define deprecate_attrib(name, prefix, level, version, msg) deprecated_message(prefix "." name, DEP_LEVEL::level, version, msg)
298 #define return_deprecated_attrib(type_macro, name, accessor, prefix, level, version, msg) \
300 deprecate_attrib(name, prefix, level, version, msg), \
304 #define return_tstring_attrib(name, accessor) \
306 if (strcmp(m, (name)) == 0) { \
307 luaW_pushtstring(L, (accessor)); \
311 #define return_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \
312 return_deprecated_attrib(return_tstring_attrib, name, accessor, prefix, level, version, msg)
314 #define return_cstring_attrib(name, accessor) \
316 if (strcmp(m, (name)) == 0) { \
317 lua_pushstring(L, (accessor)); \
321 #define return_cstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \
322 return_deprecated_attrib(return_cstring_attrib, name, accessor, prefix, level, version, msg)
324 #define return_string_attrib(name, accessor) \
326 if (strcmp(m, (name)) == 0) { \
327 const std::string& str = (accessor); \
328 lua_pushlstring(L, str.c_str(), str.length()); \
332 #define return_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
333 return_deprecated_attrib(return_string_attrib, name, accessor, prefix, level, version, msg)
335 #define return_int_attrib(name, accessor) \
337 if (strcmp(m, (name)) == 0) { \
338 lua_pushinteger(L, (accessor)); \
342 #define return_int_attrib_deprecated(name, prefix, level, version, msg, accessor) \
343 return_deprecated_attrib(return_int_attrib, name, accessor, prefix, level, version, msg)
345 #define return_float_attrib(name, accessor) \
347 if (strcmp(m, (name)) == 0) { \
348 lua_pushnumber(L, (accessor)); \
352 #define return_float_attrib_deprecated(name, prefix, level, version, msg, accessor) \
353 return_deprecated_attrib(return_float_attrib, name, accessor, prefix, level, version, msg)
355 #define return_bool_attrib(name, accessor) \
357 if (strcmp(m, (name)) == 0) { \
358 lua_pushboolean(L, (accessor)); \
362 #define return_bool_attrib_deprecated(name, prefix, level, version, msg, accessor) \
363 return_deprecated_attrib(return_bool_attrib, name, accessor, prefix, level, version, msg)
365 #define return_cfg_attrib(name, accessor) \
367 if (strcmp(m, (name)) == 0) { \
370 luaW_pushconfig(L, cfg); \
374 #define return_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor) \
375 return_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
377 #define return_cfgref_attrib(name, accessor) \
379 if (strcmp(m, (name)) == 0) { \
380 luaW_pushconfig(L, (accessor)); \
384 #define return_cfgref_attrib_deprecated(name, prefix, level, version, msg, accessor) \
385 return_deprecated_attrib(return_cfgref_attrib, name, accessor, prefix, level, version, msg)
387 #define return_vector_string_attrib(name, accessor) \
389 if (strcmp(m, (name)) == 0) { \
390 const std::vector<std::string>& vector = (accessor); \
391 lua_createtable(L, vector.size(), 0); \
393 for (const std::string& s : vector) { \
394 lua_pushlstring(L, s.c_str(), s.length()); \
395 lua_rawseti(L, -2, i); \
401 #define return_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
402 return_deprecated_attrib(return_vector_string_attrib, name, accessor, prefix, level, version, msg)
404 #define modify_tstring_attrib(name, accessor) \
406 if (strcmp(m, (name)) == 0) { \
407 t_string value = luaW_checktstring(L, 3); \
412 #define modify_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \
413 modify_tstring_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
415 #define modify_string_attrib(name, accessor) \
417 if (strcmp(m, (name)) == 0) { \
418 const char *value = luaL_checkstring(L, 3); \
423 #define modify_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
424 modify_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
426 #define modify_int_attrib(name, accessor) \
428 if (strcmp(m, (name)) == 0) { \
429 int value = static_cast<int>(luaL_checknumber(L, 3)); \
434 #define modify_int_attrib_deprecated(name, prefix, level, version, msg, accessor) \
435 modify_int_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
437 #define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max) \
439 if (strcmp(m, (name)) == 0) { \
440 int value = static_cast<int>(luaL_checknumber(L, 3)); \
441 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \
446 #define modify_int_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max) \
447 modify_int_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)
449 #define modify_float_attrib(name, accessor) \
451 if (strcmp(m, (name)) == 0) { \
452 lua_Number value = luaL_checknumber(L, 3); \
457 #define modify_float_attrib_deprecated(name, prefix, level, version, msg, accessor) \
458 modify_float_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
460 #define modify_float_attrib_check_range(name, accessor, allowed_min, allowed_max) \
462 if (strcmp(m, (name)) == 0) { \
463 lua_Number value = luaL_checknumber(L, 3); \
464 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \
469 #define modify_float_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max) \
470 modify_float_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)
472 #define modify_bool_attrib(name, accessor) \
474 if (strcmp(m, (name)) == 0) { \
475 bool value = luaW_toboolean(L, 3); \
480 #define modify_bool_attrib_deprecated(name, prefix, level, version, msg, accessor) \
481 modify_bool_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
483 #define modify_cfg_attrib(name, accessor) \
485 if (strcmp(m, (name)) == 0) { \
486 const config& cfg = luaW_checkconfig(L, 3); \
491 #define modify_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor) \
492 modify_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
494 #define modify_vector_string_attrib(name, accessor) \
496 if (strcmp(m, (name)) == 0) { \
497 std::vector<std::string> value; \
498 char const* message = "table with unnamed indices holding strings expected"; \
499 if (!lua_istable(L, 3)) return luaL_argerror(L, 3, message); \
500 unsigned length = lua_rawlen(L, 3); \
501 for (unsigned i = 1; i <= length; ++i) { \
502 lua_rawgeti(L, 3, i); \
503 char const* string = lua_tostring(L, 4); \
504 if(!string) return luaL_argerror(L, 2 + i, message); \
505 value.push_back(string); \
512 #define modify_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
513 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.
Efficiently creates new LUA "named tuples" with the specified field names.
static int impl_set(lua_State *L)
static std::string build_key(const std::vector< std::string > &names)
static int impl_tostring(lua_State *L)
lua_named_tuple_builder(const std::vector< std::string > &names)
static int impl_compare(lua_State *L)
void push(lua_State *L) const
Push an empty "named tuple" onto the stack.
static int impl_dir(lua_State *L)
const std::vector< std::string > names_
static int impl_get(lua_State *L)
static constexpr std::string_view base_name_
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)
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