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  

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  

#define QTLUA_PROPERTY(type, member)  

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 QTLUA_PROPERTY_ACCESSORS(member)  

Define simple inline accessors function for the specified member

This macro expands to:

#define QTLUA_PROPERTY_ENTRY(class_, member)  

Property table entry with get and set accessors

#define QTLUA_PROPERTY_ENTRY_GET(class_, member)  

Property table entry with get accessor only

#define QTLUA_PROPERTY_ENTRY_SET(class_, member)  

Property table entry with set accessor only

#define QTLUA_PROPERTY_GET(member)  

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 QTLUA_PROPERTY_SET(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

struct member_s  

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

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

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.

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

virtual Ref<Iterator> new_iterator(State &ls)  

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.

Shortcut for Ref smart pointer class to UserObject type provided for convenience

virtual bool support(Value::Operation c) const  

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 Value::support function.

Valid XHTML 1.0 StrictGenerated by diaxen on Mon Aug 15 03:23:06 2011 using MkDoc