The Battle for Wesnoth  1.19.7+dev
Classes | Macros | Enumerations | Functions
lua_attributes.hpp File Reference
#include "config.hpp"
#include "map/location.hpp"
#include "variable_info.hpp"
#include <string>
#include <string_view>
#include <vector>
Include dependency graph for lua_attributes.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  luaW_Registry
 Holds a lookup table for members of one type of object. More...
 
struct  lua_getter< object_type, value_type >
 
struct  lua_setter< object_type, value_type >
 
struct  lua_validator< object_type >
 

Macros

#define LATTR_MAKE_UNIQUE_ID(base, id, obj_name)   BOOST_PP_CAT(BOOST_PP_CAT(base, id), BOOST_PP_CAT(_for_, obj_name))
 
#define LATTR_GETTER5(name, value_type, obj_type, obj_name, id)
 
#define LATTR_SETTER5(name, value_type, obj_type, obj_name, id)
 
#define LATTR_VALID5(name, obj_type, obj_name, id)
 
#define LATTR_GETTER(name, value_type, obj_type, obj_name)   LATTR_GETTER5(name, value_type, obj_type, obj_name, __LINE__)
 
#define LATTR_SETTER(name, value_type, obj_type, obj_name)   LATTR_SETTER5(name, value_type, obj_type, obj_name, __LINE__)
 
#define LATTR_VALID(name, obj_type, obj_name)   LATTR_VALID5(name, obj_type, obj_name, __LINE__)
 

Enumerations

enum class  lua_attrfunc_type { getter , setter , validator }
 

Functions

template<typename T >
std::decay_t< T > lua_check (lua_State *L, int n)
 
template<typename object_type , typename value_type , typename action_type , lua_attrfunc_type type>
void register_lua_attribute (const char *name)
 

Macro Definition Documentation

◆ LATTR_GETTER

#define LATTR_GETTER (   name,
  value_type,
  obj_type,
  obj_name 
)    LATTR_GETTER5(name, value_type, obj_type, obj_name, __LINE__)
Parameters
namestring attribute name
value_typethe type of the attribute, for example int or std::string
obj_typethe type of the object, for example lua_unit
obj_namea name for the variable that will hold the object

Definition at line 173 of file lua_attributes.hpp.

◆ LATTR_GETTER5

#define LATTR_GETTER5 (   name,
  value_type,
  obj_type,
  obj_name,
  id 
)
Value:
struct LATTR_MAKE_UNIQUE_ID(getter_, id, obj_name) : public lua_getter<obj_type, value_type> { \
using object_type = obj_type; \
virtual value_type get(lua_State* L, const object_type& obj_name) const override; \
}; \
struct LATTR_MAKE_UNIQUE_ID(getter_adder_, id, obj_name) { \
LATTR_MAKE_UNIQUE_ID(getter_adder_, id, obj_name) () \
{ \
register_lua_attribute<obj_type, value_type, LATTR_MAKE_UNIQUE_ID(getter_, id, obj_name), lua_attrfunc_type::getter>(name); \
} \
}; \
static LATTR_MAKE_UNIQUE_ID(getter_adder_, id, obj_name) LATTR_MAKE_UNIQUE_ID(getter_adder_instance_, id, obj_name) ; \
value_type LATTR_MAKE_UNIQUE_ID(getter_, id, obj_name)::get([[maybe_unused]] lua_State* L, const LATTR_MAKE_UNIQUE_ID(getter_, id, obj_name)::object_type& obj_name) const
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:198
#define LATTR_MAKE_UNIQUE_ID(base, id, obj_name)
CURSOR_TYPE get()
Definition: cursor.cpp:216

Definition at line 122 of file lua_attributes.hpp.

◆ LATTR_MAKE_UNIQUE_ID

#define LATTR_MAKE_UNIQUE_ID (   base,
  id,
  obj_name 
)    BOOST_PP_CAT(BOOST_PP_CAT(base, id), BOOST_PP_CAT(_for_, obj_name))

Definition at line 120 of file lua_attributes.hpp.

◆ LATTR_SETTER

#define LATTR_SETTER (   name,
  value_type,
  obj_type,
  obj_name 
)    LATTR_SETTER5(name, value_type, obj_type, obj_name, __LINE__)

Definition at line 175 of file lua_attributes.hpp.

◆ LATTR_SETTER5

#define LATTR_SETTER5 (   name,
  value_type,
  obj_type,
  obj_name,
  id 
)
Value:
struct LATTR_MAKE_UNIQUE_ID(setter_, id, obj_name) : public lua_setter<obj_type, value_type> { \
using object_type = obj_type; \
void set(lua_State* L, object_type& obj_name, const value_type& value) const override; \
}; \
struct LATTR_MAKE_UNIQUE_ID(setter_adder_, id, obj_name) { \
LATTR_MAKE_UNIQUE_ID(setter_adder_, id, obj_name) ()\
{ \
register_lua_attribute<obj_type, value_type, LATTR_MAKE_UNIQUE_ID(setter_, id, obj_name), lua_attrfunc_type::setter>(name); \
} \
}; \
static LATTR_MAKE_UNIQUE_ID(setter_adder_, id, obj_name) LATTR_MAKE_UNIQUE_ID(setter_adder_instance_, id, obj_name); \
void LATTR_MAKE_UNIQUE_ID(setter_, id, obj_name)::set([[maybe_unused]] lua_State* L, LATTR_MAKE_UNIQUE_ID(setter_, id, obj_name)::object_type& obj_name, const value_type& value) const
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:176

Definition at line 137 of file lua_attributes.hpp.

◆ LATTR_VALID

#define LATTR_VALID (   name,
  obj_type,
  obj_name 
)    LATTR_VALID5(name, obj_type, obj_name, __LINE__)

Definition at line 177 of file lua_attributes.hpp.

◆ LATTR_VALID5

#define LATTR_VALID5 (   name,
  obj_type,
  obj_name,
  id 
)
Value:
struct LATTR_MAKE_UNIQUE_ID(check_, id, obj_name) : public lua_validator<obj_type> { \
using object_type = obj_type; \
bool is_active(lua_State* L, const object_type& obj_name) const override; \
}; \
struct LATTR_MAKE_UNIQUE_ID(check_adder_, id, obj_name) { \
LATTR_MAKE_UNIQUE_ID(check_adder_, id, obj_name) ()\
{ \
register_lua_attribute<obj_type, void, LATTR_MAKE_UNIQUE_ID(check_, id, obj_name), lua_attrfunc_type::validator>(name); \
} \
}; \
static LATTR_MAKE_UNIQUE_ID(check_adder_, id, obj_name) LATTR_MAKE_UNIQUE_ID(check_adder_instance_, id, obj_name); \
bool LATTR_MAKE_UNIQUE_ID(check_, id, obj_name)::is_active([[maybe_unused]] lua_State* L, const LATTR_MAKE_UNIQUE_ID(check_, id, obj_name)::object_type& obj_name) const
static bool is_active(const widget *wgt)
Definition: window.cpp:1267
virtual bool is_active(lua_State *L, const object_type &obj) const =0

Definition at line 152 of file lua_attributes.hpp.

Enumeration Type Documentation

◆ lua_attrfunc_type

enum lua_attrfunc_type
strong
Enumerator
getter 
setter 
validator 

Definition at line 63 of file lua_attributes.hpp.

Function Documentation

◆ lua_check()

template<typename T >
std::decay_t<T> lua_check ( lua_State *  L,
int  n 
)

Definition at line 411 of file push_check.hpp.

References n.

Referenced by impl_source_set(), and read_event_name().

◆ register_lua_attribute()

template<typename object_type , typename value_type , typename action_type , lua_attrfunc_type type>
void register_lua_attribute ( const char *  name)

Definition at line 89 of file lua_attributes.hpp.

References cursor::get(), getter, luaW_Registry::lookup, lua_push(), setter, and validator.