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);
195 template<
typename... T>
225 bool luaW_pcall(lua_State *L,
int nArgs,
int nRets,
bool allow_wml_error =
false);
232 int luaW_type_error(lua_State *L,
int narg,
const char* kpath,
const char *tname);
238 #define deprecate_attrib(name, prefix, level, version, msg) deprecated_message(prefix "." name, DEP_LEVEL::level, version, msg)
240 #define return_deprecated_attrib(type_macro, name, accessor, prefix, level, version, msg) \
242 deprecate_attrib(name, prefix, level, version, msg), \
246 #define return_tstring_attrib(name, accessor) \
248 if (strcmp(m, (name)) == 0) { \
249 luaW_pushtstring(L, (accessor)); \
253 #define return_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \
254 return_deprecated_attrib(return_tstring_attrib, name, accessor, prefix, level, version, msg)
256 #define return_cstring_attrib(name, accessor) \
258 if (strcmp(m, (name)) == 0) { \
259 lua_pushstring(L, (accessor)); \
263 #define return_cstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \
264 return_deprecated_attrib(return_cstring_attrib, name, accessor, prefix, level, version, msg)
266 #define return_string_attrib(name, accessor) \
268 if (strcmp(m, (name)) == 0) { \
269 const std::string& str = (accessor); \
270 lua_pushlstring(L, str.c_str(), str.length()); \
274 #define return_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
275 return_deprecated_attrib(return_string_attrib, name, accessor, prefix, level, version, msg)
277 #define return_int_attrib(name, accessor) \
279 if (strcmp(m, (name)) == 0) { \
280 lua_pushinteger(L, (accessor)); \
284 #define return_int_attrib_deprecated(name, prefix, level, version, msg, accessor) \
285 return_deprecated_attrib(return_int_attrib, name, accessor, prefix, level, version, msg)
287 #define return_float_attrib(name, accessor) \
289 if (strcmp(m, (name)) == 0) { \
290 lua_pushnumber(L, (accessor)); \
294 #define return_float_attrib_deprecated(name, prefix, level, version, msg, accessor) \
295 return_deprecated_attrib(return_float_attrib, name, accessor, prefix, level, version, msg)
297 #define return_bool_attrib(name, accessor) \
299 if (strcmp(m, (name)) == 0) { \
300 lua_pushboolean(L, (accessor)); \
304 #define return_bool_attrib_deprecated(name, prefix, level, version, msg, accessor) \
305 return_deprecated_attrib(return_bool_attrib, name, accessor, prefix, level, version, msg)
307 #define return_cfg_attrib(name, accessor) \
309 if (strcmp(m, (name)) == 0) { \
312 luaW_pushconfig(L, cfg); \
316 #define return_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor) \
317 return_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
319 #define return_cfgref_attrib(name, accessor) \
321 if (strcmp(m, (name)) == 0) { \
322 luaW_pushconfig(L, (accessor)); \
326 #define return_cfgref_attrib_deprecated(name, prefix, level, version, msg, accessor) \
327 return_deprecated_attrib(return_cfgref_attrib, name, accessor, prefix, level, version, msg)
329 #define return_vector_string_attrib(name, accessor) \
331 if (strcmp(m, (name)) == 0) { \
332 const std::vector<std::string>& vector = (accessor); \
333 lua_createtable(L, vector.size(), 0); \
335 for (const std::string& s : vector) { \
336 lua_pushlstring(L, s.c_str(), s.length()); \
337 lua_rawseti(L, -2, i); \
343 #define return_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
344 return_deprecated_attrib(return_vector_string_attrib, name, accessor, prefix, level, version, msg)
346 #define modify_tstring_attrib(name, accessor) \
348 if (strcmp(m, (name)) == 0) { \
349 t_string value = luaW_checktstring(L, 3); \
354 #define modify_tstring_attrib_deprecated(name, prefix, level, version, msg, accessor) \
355 modify_tstring_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
357 #define modify_string_attrib(name, accessor) \
359 if (strcmp(m, (name)) == 0) { \
360 const char *value = luaL_checkstring(L, 3); \
365 #define modify_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
366 modify_string_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
368 #define modify_int_attrib(name, accessor) \
370 if (strcmp(m, (name)) == 0) { \
371 int value = static_cast<int>(luaL_checknumber(L, 3)); \
376 #define modify_int_attrib_deprecated(name, prefix, level, version, msg, accessor) \
377 modify_int_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
379 #define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max) \
381 if (strcmp(m, (name)) == 0) { \
382 int value = static_cast<int>(luaL_checknumber(L, 3)); \
383 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \
388 #define modify_int_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max) \
389 modify_int_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)
391 #define modify_float_attrib(name, accessor) \
393 if (strcmp(m, (name)) == 0) { \
394 lua_Number value = luaL_checknumber(L, 3); \
399 #define modify_float_attrib_deprecated(name, prefix, level, version, msg, accessor) \
400 modify_float_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
402 #define modify_float_attrib_check_range(name, accessor, allowed_min, allowed_max) \
404 if (strcmp(m, (name)) == 0) { \
405 lua_Number value = luaL_checknumber(L, 3); \
406 if (value < (allowed_min) || (allowed_max) < value) return luaL_argerror(L, 3, "out of bounds"); \
411 #define modify_float_attrib_check_range_deprecated(name, prefix, level, version, msg, accessor, allowed_min, allowed_max) \
412 modify_float_attrib_check_range(name, deprecate_attrib(name, prefix, level, version, msg); accessor, allowed_min, allowed_max)
414 #define modify_bool_attrib(name, accessor) \
416 if (strcmp(m, (name)) == 0) { \
417 bool value = luaW_toboolean(L, 3); \
422 #define modify_bool_attrib_deprecated(name, prefix, level, version, msg, accessor) \
423 modify_bool_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
425 #define modify_cfg_attrib(name, accessor) \
427 if (strcmp(m, (name)) == 0) { \
428 const config& cfg = luaW_checkconfig(L, 3); \
433 #define modify_cfg_attrib_deprecated(name, prefix, level, version, msg, accessor) \
434 modify_cfg_attrib(name, deprecate_attrib(name, prefix, level, version, msg); accessor)
436 #define modify_vector_string_attrib(name, accessor) \
438 if (strcmp(m, (name)) == 0) { \
439 std::vector<std::string> value; \
440 char const* message = "table with unnamed indices holding strings expected"; \
441 if (!lua_istable(L, 3)) return luaL_argerror(L, 3, message); \
442 unsigned length = lua_rawlen(L, 3); \
443 for (unsigned i = 1; i <= length; ++i) { \
444 lua_rawgeti(L, 3, i); \
445 char const* string = lua_tostring(L, 4); \
446 if(!string) return luaL_argerror(L, 2 + i, message); \
447 value.push_back(string); \
454 #define modify_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor) \
455 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.
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