ArrayProxy class reference
[Container proxies module]

Declaration  

#include <QtLua/ArrayProxy>

namespace QtLua {
template <typename T> class ArrayProxy;
};

This class is a member of the QtLua namespace.

Description  

This template class may be used to expose a C array to lua script for read and write access. The ArrayProxyRo class may be used for read only access.

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

First entry has index 1. Lua nil value is returned if index is above array size.

Lua operator # returns the array size. Lua operator - returns a lua table copy of the container.

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

// code from examples/cpp/proxy/arrayproxy_string.cc:34

QtLua::String array[4];

// Array proxy which provides access to our array from lua.
QtLua::ArrayProxy<QtLua::String> proxy(array, 4);

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

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

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

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

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

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

Members  

Inherited members  

Types  

Functions  

Members detail  

ArrayProxy()  

Create a ArrayProxy object

ArrayProxy(T *array, unsigned int size)  

Create a ArrayProxy object

typedef Ref<const ArrayProxy, ArrayProxy> const_ptr  

Shortcut for Ref smart pointer class to ArrayProxy 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 ArrayProxy type provided for convenience

void set_container(T *array, unsigned int size)  

Attach or detach associated array. argument may be NULL

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