QLua
Lua-Qt bindings
Classes | Public Types | Public Member Functions
qlua::LuaContext Class Reference

Lua context. Creates or wraps an existing Lua state. More...

#include <LuaContext.h>

Collaboration diagram for qlua::LuaContext:
Collaboration graph
[legend]

List of all members.

Classes

struct  Method
 Stores information used at method invocation time.

Public Types

enum  ObjectDeleteMode { QOBJ_NO_DELETE, QOBJ_IMMEDIATE_DELETE, QOBJ_DELETE_LATER }
 Delete mode: Specify how/if object shall be garbage collected. More...

Public Member Functions

 LuaContext (lua_State *L=0)
lua_State * LuaState () const
 Return Lua state.
void Eval (const char *code)
 Evaluate Lua code.
void AddQVariantMap (const QVariantMap &vm, const char *name=0)
 Add QVariantMap: Either push it on the stack or set it as global.
void AddQVariantList (const QVariantList &vl, const char *name=0)
 Add QVariantList: Either push it on the stack or set it as global.
void AddQStringList (const QStringList &sl, const char *name=0)
 Add QStringList: Either push it on the stack or set it as global.
template<typename T >
void AddQList (const QList< T > &l, const char *name=0)
 Add QList of numeric values: Either push it on the stack or set it as global.
void AddQObject (QObject *obj, const char *tableName=0, bool cache=false, ObjectDeleteMode deleteMode=QOBJ_NO_DELETE, const ILuaSignatureMapper &mapper=LuaDefaultSignatureMapper(), const QStringList &methodNames=QStringList(), const QList< QMetaMethod::MethodType > &methodTypes=QList< QMetaMethod::MethodType >())
 Add QObject to Lua context as a Lua table.
bool OwnQObjects () const
 Return value of global garbage collection policy.
 ~LuaContext ()
 Destructor: Destroys Lua state if owned by this object.

Detailed Description

Lua context. Creates or wraps an existing Lua state.

This class is the interface exposed by QLua to client code. Use the provided method to add QObjects and other types the Lua context and to evaluate Lua code. LuaContext is also used internally by other classes to add QObjects returned by methods or received from signals to the Lua context.


Member Enumeration Documentation

Delete mode: Specify how/if object shall be garbage collected.

Enumerator:
QOBJ_NO_DELETE 

Lifetime not managed by Lua; never garbage collected.

QOBJ_IMMEDIATE_DELETE 

Garbage collected: delete used.

QOBJ_DELETE_LATER 

Garbage collected: QObject::deleteLater() used.


Constructor & Destructor Documentation

qlua::LuaContext::LuaContext ( lua_State *  L = 0)

Constructor: Create qlua table with QLua interface.

Parameters:
Lif not null the passed Lua state is used, otherwise a new one is created.

Member Function Documentation

template<typename T >
void qlua::LuaContext::AddQList ( const QList< T > &  l,
const char *  name = 0 
) [inline]

Add QList of numeric values: Either push it on the stack or set it as global.

Parameters:
lQList
nameglobal name; if null value is left on the Lua stack.
void qlua::LuaContext::AddQObject ( QObject *  obj,
const char *  tableName = 0,
bool  cache = false,
ObjectDeleteMode  deleteMode = QOBJ_NO_DELETE,
const ILuaSignatureMapper mapper = LuaDefaultSignatureMapper(),
const QStringList &  methodNames = QStringList(),
const QList< QMetaMethod::MethodType > &  methodTypes = QList< QMetaMethod::MethodType >() 
)

Add QObject to Lua context as a Lua table.

When a new QObject is added this method:

  1. adds a new QObject reference in the QObject-Method database
  2. iterates over the callable QObject's methods and for each method adds a Method object with information required to invoke the QObject method
  3. if caching is enabled it creates a Lua reference and adds the reference into the QObject-Reference database
    Parameters:
    objQObject
    tableNameglobal name of Lua table wrapping object; if null object is left on stack
    cacheif true object won't be re-added to LuaContext. If tableName is not null a new global variable pointing at the previoulsy added object will be added.
    mappermaps signature string to Lua method name; this allows to convert overloaed methods to different Lua functions.
    deleteModechoose how/if object shall be garbage collected;
    See also:
    ObjectDeleteMode
    Parameters:
    methodNamesif not empty only the methods with the names in this list are added to the Lua table
    methodTypesif not empty only the methods of the required types are added to the Lua table
void qlua::LuaContext::AddQStringList ( const QStringList &  sl,
const char *  name = 0 
) [inline]

Add QStringList: Either push it on the stack or set it as global.

Parameters:
slQStringList
nameglobal name; if null value is left on the Lua stack.
void qlua::LuaContext::AddQVariantList ( const QVariantList &  vl,
const char *  name = 0 
) [inline]

Add QVariantList: Either push it on the stack or set it as global.

Parameters:
vlQVariantList
nameglobal name; if null value is left on the Lua stack.
void qlua::LuaContext::AddQVariantMap ( const QVariantMap &  vm,
const char *  name = 0 
) [inline]

Add QVariantMap: Either push it on the stack or set it as global.

Parameters:
vmQVariantMap
nameglobal name; if null value is left on the Lua stack.
bool qlua::LuaContext::OwnQObjects ( ) const [inline]

Return value of global garbage collection policy.

The global object ownership policy is set from Lua through a call to qlua.ownQObjects(). The ownership policy affects the QObjects returned by QObject methods only.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator