QVectorProxy class reference
[Container proxies module]

Declaration  

#include <QtLua/QVectorProxy>

namespace QtLua {
template <typename Container, bool resize = false> class QVectorProxy;
};

This class is a member of the QtLua namespace.

Description  

This template class may be used to expose an attached QVector container object to lua script for read and write access. The QVectorProxyRo class may be used for read only access.

Containers may be attached and detached from the wrapper object to solve cases where we want to destroy the container when lua still holds references to the wrapper object. When no container is attached access will raise an error.

First entry has index 1. Lua nil value is returned if no such entry exists on table read. A nil value write will delete entry at given index. Write access at vector size + 1 append a new entry to the vector if the resize template argument is true.

QVector may be resized if accessing above current size, depending on resize template parameter value.

Lua operator # returns the container entry count. Lua operator - returns a lua table copy of the container.

The following example show how a QVector object can be accessed from both C++ and lua script directly:

// code from examples/cpp/proxy/qvectorproxy_string.cc:35

typedef QVector<QtLua::String> Container;

// QVector we want to access from lua
Container vector(1);

// Vector proxy which provides access to our QVector from lua.
// Our proxy is allowed to resize the QVector.
QtLua::QVectorProxy<Container, true> proxy(vector);

QtLua::State state;
state.openlib(QtLua::QtLuaLib);

// Declare a lua global variable using our QVector proxy
state["vector"] = proxy;

// Set a value in QVector
vector[0] = "foo";

// Read/Write/Resize QVector from lua using the proxy object
state.exec_statements("vector[2] = vector[1]..\"bar\" ");

// Read back value in QVector modified from lua script
std::cout << vector[1].constData() << std::endl;

// Remove entry 0 sizing down the QVector
state.exec_statements("vector[1] = nil");

// Iterate through QVector from lua script
state.exec_statements("for key, value in each(vector) do print(key, value) end");

Inheritance  

Members  

Inherited members  

Types  

Functions  

Members detail  

QVectorProxy()  

Create a QVectorProxy object

QVectorProxy(Container &vector)  

Create a QVectorProxy object

typedef Ref<const QVectorProxy, QVectorProxy> const_ptr  

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

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.

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

bool support(Value::Operation c)  

No documentation available

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