QListProxy class reference
[Container proxies module]


 
 

 
 


 
 

 
 

QListProxyRo<Container>

 
 

 
 


Declaration  

#include <QtLua/QListProxy>

namespace QtLua {
template <typename Container> class QListProxy;
};

This class is a member of the QtLua namespace.

Description  

This template class may be used to expose an attached QList container object to lua script for read and write access. The QListProxyRo 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 list size + 1 append a new entry to the list.

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

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

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

typedef QList<QtLua::String> Container;

// QList we want to access from lua
Container list;

// List proxy which provides access to our QList from lua
QtLua::QListProxy<Container> proxy(list);

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

// Declare a lua global variable using our QList proxy
state["list"] = proxy;

// Add values in QList
list << "foo" << "bar" << "FOO";

// Append an element to the QList from lua using the proxy object
state.exec_statements("list[4] = \"BAR\" ");
state.exec_statements("list[5] = \"TEST\" ");

// Read/Write element from lua
state.exec_statements("list[1] = list[1]..list[2]");

// Delete element from lua
state.exec_statements("list[3] = nil");

// Read back values in modified QList
foreach(const QtLua::String &s, list)
std::cout << s.constData() << std::endl;

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

Members  

Inherited members  

Types  

Functions  

Members detail  

QListProxy()  

Create a QListProxy object

QListProxy(Container &list)  

Create a QListProxy object

typedef Ref<const QListProxy, QListProxy> const_ptr  

Shortcut for Ref smart pointer class to QListProxy 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 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.

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

bool support(ValueBase::Operation c)  

No documentation available

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 15:29:54 2013 using MkDoc