UserObject class reference
[Base module]
Declaration
#include <QtLua/UserObject>
namespace QtLua {
template <typename T> class UserObject;
};
This class is a member of the QtLua namespace.
Description
This base class can be used to create C++ objects with named properties accessible from lua script. This is a lightweight alternative to writting a QObject based class when only set/get properties mechanism is needed.
Each property can have a set and get accessor functions registered through a static const array. Property member and accessor functions can be user defined or declared using the QTLUA_PROPERTY_GET , QTLUA_PROPERTY_SET , QTLUA_PROPERTY_ACCESSORS or QTLUA_PROPERTY macros as shown on the example below :
// code from examples/cpp/userdata/userobject.cc:24
class Test : public QtLua::UserObject<Test>
{
QTLUA_PROPERTY(int, _value);
public:
Test(int value)
: _value(value)
{
}
static const member_s member_table[];
};
const Test::member_s Test::member_table[] = {
QTLUA_PROPERTY_ENTRY(Test, _value),
};
Inheritance
Members
Inherited members
- 19 members inherited from UserData
Types
Functions
- virtual Value meta_index(State &ls, const Value &key)
- virtual void meta_newindex(State &ls, const Value &key, const Value &value)
- virtual Ref<Iterator> new_iterator(State &ls)
- virtual bool support(Value::Operation c) const
Macros
Members detail
Declare a member of given type and define a simple inline accessors function for the specified member
This macro expands to:
type member;
QTLUA_PROPERTY_ACCESSORS(member);
Define simple inline accessors function for the specified member
This macro expands to:
QTLUA_PROPERTY_GET(member)
QTLUA_PROPERTY_SET(member)
Property table entry with get and set accessors
Property table entry with get accessor only
Property table entry with set accessor only
Define a simple inline get accessor function for the specified member
This macro expands to:
inline QtLua::Value get_##member(QtLua::State &ls)
{
return QtLua::Value(ls, member);
}
Define a simple inline set accessor function for the specified member
This macro expands to:
inline void set_##member(QtLua::State &ls, const QtLua::Value &value)
{
member = value;
}
typedef Ref<const UserObject, UserObject> const_ptr
Shortcut for Ref smart pointer class to UserObject type provided for convenience
Property member entry
This virtual function overrides the meta_index
virtual function defined in the UserData
base class.
Documentation inherited from base class:
This functions is called when a table read access operation is attempted on a userdata object. The default implementation throws an error message. The UserData::support function should be reimplemented along with this function.
Parameters list:
- key: Value used as table index.
The return value is Table access result value.
This virtual function overrides the meta_newindex
virtual function defined in the UserData
base class.
Documentation inherited from base class:
This functions is called when a table write access operation is attempted on a userdata object. The default implementation throws an error message. The UserData::support function should be reimplemented along with this function.
Parameters list:
- key: Value used as table index.
- value: Value to put in table.
This virtual function overrides the new_iterator
virtual function defined in the UserData
base class.
Documentation inherited from base class:
This function may return an Iterator object used to iterate over an userdata object. The default implementation throws an error message. The UserData::support function should be reimplemented along with this function.
The return value is an Iterator based iterator object.
typedef Ref<UserObject, UserObject> ptr
Shortcut for Ref smart pointer class to UserObject type provided for convenience