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  

Types  

Private type  

Functions  

Private functions  

Private field  

Macros  

Members detail  

UserObject()  

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.

UserObject(T *obj)  

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.

#define QTLUA_PROPERTIES_TABLE(class_name, ...)  

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 } };

#define QTLUA_PROPERTY(type, member)  

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);

#define 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:

#define QTLUA_PROPERTY_ACCESSORS_F(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:

#define QTLUA_PROPERTY_ACCESSOR_F_GET(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());
}

#define QTLUA_PROPERTY_ACCESSOR_F_SET(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);
}

#define QTLUA_PROPERTY_ACCESSOR_GET(member)  

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);
}

#define QTLUA_PROPERTY_ACCESSOR_SET(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;
}

#define QTLUA_PROPERTY_ENTRY(class_name, name, member)  

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 }

#define QTLUA_PROPERTY_ENTRY_GET(class_name, name, 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 }

#define QTLUA_PROPERTY_ENTRY_SET(class_name, name, 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 }

#define QTLUA_PROPERTY_ENTRY_U(class_name, name, get, set)  

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 }

#define QTLUA_PROPERTY_ENTRY_U_GET(class_name, 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 }

#define QTLUA_PROPERTY_ENTRY_U_SET(class_name, name, set)  

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 }

#define QTLUA_PROPERTY_GET(type, member)  

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.

#define QTLUA_PROPERTY_SET(type, member)  

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.

#define QTLUA_USEROBJECT(class_name)  

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[];

T *_obj  

This variable is declared in QtLua/qtluauserobject.hh source file, line 88.

This member access is private.

virtual void completion_patch(String &path, String &entry, int &offset)  

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.

virtual bool meta_contains(State *ls, const Value &key)  

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.

virtual Value meta_index(State *ls, const Value &key)  

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.

virtual void meta_newindex(State *ls, const Value &key, const Value &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.

virtual Ref<Iterator> new_iterator(State *ls)  

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.

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.

struct _qtlua_property_s  

This struct is for internal use only.

This struct is declared in QtLua/qtluauserobject.hh source file, line 105.

Property member entry

FieldDescription
const char *name;Lua property name
void (T::*set)(State *ls, const Value &value) ;Pointer to property set accesor function for lua
Value (T::*get)(State *ls) ;Pointer to property get accesor function for lua

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 16:23:03 2013 using MkDoc