QHashProxy class reference
[Container proxies module]
Declaration
#include <QtLua/QHashProxy>
namespace QtLua {
template <typename Container> class QHashProxy;
};
This class is a member of the QtLua namespace.
This template class is declared in QtLua/qtluaqhashproxy.hh source file, line 138.
Description
This template class may be used to expose an attached QHash or QMap container object to lua script for read and write access. The QHashProxyRo 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.
Lua nil value is returned if no such entry exists on table read. A nil value write will delete entry at access index.
Lua operator # returns the container entry count. Lua operator - returns a lua table copy of the container.
The following example show how a QMap object indexed with String objects can be accessed from both C++ and lua script directly:
// code from examples/cpp/proxy/qmapproxy_string.cc:35
typedef QMap<QtLua::String, QtLua::String> Container;
// QMap we want to access from lua
Container map;
// Map proxy which provides access to our QMap from lua
QtLua::QHashProxy<Container> proxy(map);
QtLua::State state;
state.openlib(QtLua::QtLuaLib);
// Declare a lua global variable using our map proxy
state["map"] = proxy;
// Insert a value in QMap
map["key1"] = "value";
// Read/Write in QMap from lua using the proxy object
state.exec_statements("map.key2 = map.key1");
// Read back value in QMap inserted from lua script
std::cout << map["key2"].constData() << std::endl;
// Remove key2 entry from lua script
state.exec_statements("map.key2 = nil");
// Iterate through QMap from lua script
state.exec_statements("for key, value in each(map) do print(key, value) end");
Members
Inherited members
- 30 members inherited from QHashProxyRo<Container>
Types
Functions
- QHashProxy()
- QHashProxy(Container &hash)
- virtual void meta_newindex(State *ls, const Value &key, const Value &value)
- bool support(ValueBase::Operation c)
Members detail
This constructor is declared in QtLua/qtluaqhashproxy.hh source file, line 145.
Create a QHashProxy object
This constructor is declared in QtLua/qtluaqhashproxy.hh source file, line 147.
Create a QHashProxy object
typedef Ref<const QHashProxy, QHashProxy> const_ptr
This typedef is declared in QTLUA_REFTYPE function like macro expansion, line 3 in QtLua/qtluaqhashproxy.hh source file, line 142.
Shortcut for Ref smart pointer class to QHashProxy type provided for convenience
This virtual function is declared in QtLua/qtluaqhashproxy.hh source file, line 149.
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<QHashProxy, QHashProxy> ptr
This typedef is declared in QTLUA_REFTYPE function like macro expansion, line 5 in QtLua/qtluaqhashproxy.hh source file, line 142.
Shortcut for Ref smart pointer class to QHashProxy type provided for convenience
bool support(ValueBase::Operation c)
This function is declared in QtLua/qtluaqhashproxy.hh source file, line 150.