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.
This template class is declared in QtLua/qtluauserobject.hh source file, line 61.
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. The class doesn't need to be a QObject and doesn't require moc pre-processing.
Each property must be described in a table and can have an associated lua_set* and/or lua_get* accessor function. Lua accessors functions must be able to convert between a Value object and property field type. Property members and lua accessor functions can be user defined or declared using the QTLUA_PROPERTY family of macros as shown in the example below:
// code from examples/cpp/userdata/userobject.cc:24
class Test : public QtLua::UserObject<Test>
{
QTLUA_USEROBJECT(Test);
QTLUA_PROPERTY(int, _value);
public:
Test(int value)
: _value(value)
{
}
};
QTLUA_PROPERTIES_TABLE(Test,
QTLUA_PROPERTY_ENTRY(Test, "value", _value)
);
In the next example our class already needs to inherit from an other UserData based class for some reasons. We declare the UserObject class as a member and forward table accesses to it. This example also shows how to write lua accessors by hand:
// code from examples/cpp/userdata/userobject2.cc:24
class Test : public QtLua::UserData
{
QTLUA_USEROBJECT(Test);
QtLua::UserObject<Test> _uo;
int _value;
QtLua::Value meta_index(QtLua::State *ls, const QtLua::Value &key)
{
return _uo.meta_index(ls, key);
}
bool meta_contains(QtLua::State *ls, const QtLua::Value &key)
{
return _uo.meta_contains(ls, key);
}
void meta_newindex(QtLua::State *ls, const QtLua::Value &key, const QtLua::Value &value)
{
return _uo.meta_newindex(ls, key, value);
}
QtLua::Ref<QtLua::Iterator> new_iterator(QtLua::State *ls)
{
return _uo.new_iterator(ls);
}
bool support(QtLua::Value::Operation c) const
{
return _uo.support(c) || QtLua::UserData::support(c);
}
QtLua::Value lua_get_value(QtLua::State *ls)
{
return QtLua::Value(ls, _value);
}
void lua_set_value(QtLua::State *ls, const QtLua::Value &value)
{
_value = value;
}
public:
Test(int value)
: _uo(this), // pass pointer to the object which holds properties
_value(value)
{
_uo.ref_delegate(this);
}
};
QTLUA_PROPERTIES_TABLE(Test,
QTLUA_PROPERTY_ENTRY_U(Test, "value", lua_get_value, lua_set_value)
);
Members
Inherited members
- 30 members inherited from UserData
Types
- typedef [...] const_ptr
- typedef [...] ptr
- struct _qtlua_property_s
Private type
- class UserObjectIterator
Functions
- UserObject()
- UserObject(T *obj)
- virtual bool meta_contains(State *ls, const Value &key)
- 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(ValueBase::Operation c) const
Private functions
- virtual void completion_patch(String &path, String &entry, int &offset)
- int get_entry(const String &name)
Private field
- T *_obj
Macros
- QTLUA_PROPERTIES_TABLE
- QTLUA_PROPERTY
- QTLUA_PROPERTY_ACCESSORS
- QTLUA_PROPERTY_ACCESSORS_F
- QTLUA_PROPERTY_ACCESSOR_F_GET
- QTLUA_PROPERTY_ACCESSOR_F_SET
- QTLUA_PROPERTY_ACCESSOR_GET
- QTLUA_PROPERTY_ACCESSOR_SET
- QTLUA_PROPERTY_ENTRY
- QTLUA_PROPERTY_ENTRY_GET
- QTLUA_PROPERTY_ENTRY_SET
- QTLUA_PROPERTY_ENTRY_U
- QTLUA_PROPERTY_ENTRY_U_GET
- QTLUA_PROPERTY_ENTRY_U_SET
- QTLUA_PROPERTY_GET
- QTLUA_PROPERTY_SET
- QTLUA_USEROBJECT
Members detail
This constructor is declared in QtLua/qtluauserobject.hh source file, line 96.
This constructor must be used when the class which contains properties inherit from UserObject.
This constructor is declared in QtLua/qtluauserobject.hh source file, line 101.
This constructor must be used when the class which contains properties does not inherit from UserObject. Pointer to properties object must be provided.
This macro is declared in QtLua/qtluauserobject.hh source file, line 130.
This macro must be used once at global scope to list available properties and specify allowed access.
This macro expands to:
const class_name::_qtlua_property_s class_name::_qtlua_properties_table[] = { __VA_ARGS__, { 0 } };
This macro is declared in QtLua/qtluauserobject.hh source file, line 198.
Declare a member of given type and define lua accessor functions for the specified member. This is a convenience macro, member and accessor functions can be defined directly.
This macro expands to:
type member;
QTLUA_PROPERTY_ACCESSORS(member);
This macro is declared in QtLua/qtluauserobject.hh source file, line 159.
Define simple inline accessors function for the specified member
This macro expands to:
QTLUA_PROPERTY_ACCESSOR_GET(member)
QTLUA_PROPERTY_ACCESSOR_SET(member)
This macro is declared in QtLua/qtluauserobject.hh source file, line 188.
Define lua accessors functions for the specified member which rely on regular C++ accessors.
This macro expands to:
QTLUA_PROPERTY_ACCESSOR_F_GET(member)
QTLUA_PROPERTY_ACCESSOR_F_SET(member)
This macro is declared in QtLua/qtluauserobject.hh source file, line 168.
Define a lua get accessor function for the specified member which relies on a regular C++ get accessor functions.
This macro expands to:
inline QtLua::Value lua_get_##member(QtLua::State *ls)
{
return QtLua::Value(ls, get_##member());
}
This macro is declared in QtLua/qtluauserobject.hh source file, line 178.
Define a lua set accessor function for the specified member which relies on a regular C++ set accessor functions.
This macro expands to:
inline void lua_set_##member(QtLua::State *ls, const QtLua::Value &value)
{
set_##member(value);
}
This macro is declared in QtLua/qtluauserobject.hh source file, line 139.
Define a lua get accessor function for the specified member
This macro expands to:
inline QtLua::Value lua_get_##member(QtLua::State *ls)
{
return QtLua::Value(ls, member);
}
This macro is declared in QtLua/qtluauserobject.hh source file, line 149.
Define a lua set accessor function for the specified member
This macro expands to:
inline void lua_set_##member(QtLua::State *ls, const QtLua::Value &value)
{
member = value;
}
This macro is declared in QtLua/qtluauserobject.hh source file, line 223.
Property table entry with get and set accessors.
This macro expands to:
{ name, &class_name::lua_set_##member, &class_name::lua_get_##member }
This macro is declared in QtLua/qtluauserobject.hh source file, line 229.
Property table entry with get accessor only.
This macro expands to:
{ name, 0, &class_name::lua_get_##member }
This macro is declared in QtLua/qtluauserobject.hh source file, line 235.
Property table entry with set accessor only.
This macro expands to:
{ name, &class_name::lua_set_##member, 0 }
This macro is declared in QtLua/qtluauserobject.hh source file, line 241.
Property table entry with user defined lua accessor functions.
This macro expands to:
{ name, &class_name::set, &class_name::get }
This macro is declared in QtLua/qtluauserobject.hh source file, line 247.
Property table entry with user defined lua get accessor function only.
This macro expands to:
{ name, 0, &class_name::get }
This macro is declared in QtLua/qtluauserobject.hh source file, line 253.
Property table entry with user defined lua set accessor function only.
This macro expands to:
{ name, &class_name::set, 0 }
This macro is declared in QtLua/qtluauserobject.hh source file, line 207.
Declare a member of given type and define a lua get accessor function for the specified member.
This macro expands to:
type member;
QTLUA_PROPERTY_ACCESSOR_GET(member);
See also QTLUA_PROPERTY macro.
This macro is declared in QtLua/qtluauserobject.hh source file, line 216.
Declare a member of given type and define a lua set accessor function for the specified member.
This macro expands to:
type member;
QTLUA_PROPERTY_ACCESSOR_SET(member);
See also QTLUA_PROPERTY macro.
This macro is declared in QtLua/qtluauserobject.hh source file, line 119.
This macro must appears once in class body which holds property declarations.
This macro expands to:
friend class QtLua::UserObject<class_name>;
typedef QtLua::UserObject<class_name>::_qtlua_property_s _qtlua_property_s;
static const _qtlua_property_s _qtlua_properties_table[];
This variable is declared in QtLua/qtluauserobject.hh source file, line 88.
This member access is private.
This virtual function is declared in QtLua/qtluauserobject.hh source file, line 90.
This member access is private.
This virtual function overrides the completion_patch
virtual function defined in the UserData
base class.
Documentation inherited from base class:
This function may be reimplemented to further modify completion result on console line when completed to a UserData value. This is usefull to append a dot or a pair of brackets access operator to the userdata value name for instance.
Parameters list:
- path: Completion result tables path to userdata value.
- entry: Completion result userdata name. May append to this string directly.
- offset: Cursor offset. May be decreased to place cursor between inserted brackets for instance.
typedef Ref<const UserObject, UserObject> const_ptr
This typedef is declared in QTLUA_REFTYPE function like macro expansion, line 3 in QtLua/qtluauserobject.hh source file, line 63.
Shortcut for Ref smart pointer class to UserObject type provided for convenience
int get_entry(const String &name)
This function is declared in QtLua/qtluauserobject.hh source file, line 87.
This member access is private.
This virtual function is declared in QtLua/qtluauserobject.hh source file, line 112.
This virtual function overrides the meta_contains
virtual function defined in the UserData
base class.
Documentation inherited from base class:
This function returns true if either the ValueBase::OpIndex operation or the ValueBase::OpNewindex operation is supported and an entry is associated to the given key.
The default implementation returns !meta_index(ls, key).is_nil() or false if UserData::meta_index throws.
This virtual function is declared in QtLua/qtluauserobject.hh source file, line 111.
This virtual function overrides the meta_index
virtual function defined in the UserData
base class.
Documentation inherited from base class:
This function 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 must be reimplemented along with this function to report ValueBase::OpIndex as supported.
Parameters list:
- key: Value used as table index.
The return value is Table access result value.
This virtual function is declared in QtLua/qtluauserobject.hh source file, line 113.
This virtual function overrides the meta_newindex
virtual function defined in the UserData
base class.
Documentation inherited from base class:
This function 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 must be reimplemented along with this function to report ValueBase::OpNewindex as supported.
Parameters list:
- key: Value used as table index.
- value: Value to put in table.
This virtual function is declared in QtLua/qtluauserobject.hh source file, line 114.
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 must be reimplemented along with this function to report ValueBase::OpIterate as supported.
The return value is an Iterator based iterator object.
typedef Ref<UserObject, UserObject> ptr
This typedef is declared in QTLUA_REFTYPE function like macro expansion, line 5 in QtLua/qtluauserobject.hh source file, line 63.
Shortcut for Ref smart pointer class to UserObject type provided for convenience
virtual bool support(ValueBase::Operation c) const
This virtual function is declared in QtLua/qtluauserobject.hh source file, line 115.
This virtual function overrides the support
virtual function defined in the UserData
base class.
Documentation inherited from base class:
Check given operation support.
See also ValueBase::support function.
This struct is for internal use only.
This struct is declared in QtLua/qtluauserobject.hh source file, line 105.
Property member entry