QVectorProxy class reference
[Container proxies module]
Declaration
#include <QtLua/QVectorProxy>
namespace QtLua {
template <typename Container, unsigned int max_resize = 0, unsigned int min_resize = 0> 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 when reading above vector size. Write access above current vector size increase vector size as long as the new size is not higher than max_resize. Writing a nil value truncates vector by discarding value at accessed index and all values at higher indexes provided that the new size is not lower than min_resize.
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, 10> 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");
Members
Inherited members
- 25 members inherited from QVectorProxyRo<Container, max_resize, min_resize>
Types
Functions
- QVectorProxy()
- QVectorProxy(Container &vector)
- virtual void meta_newindex(State *ls, const Value &key, const Value &value)
- bool support(ValueBase::Operation c)
Members detail
Create a QVectorProxy object
Create a QVectorProxy object
typedef Ref<const QVectorProxy, QVectorProxy> const_ptr
Shortcut for Ref smart pointer class to QVectorProxy type provided for convenience
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.
typedef Ref<QVectorProxy, QVectorProxy> ptr
Shortcut for Ref smart pointer class to QVectorProxy type provided for convenience
bool support(ValueBase::Operation c)
No documentation available