Publics and protected Qt slots can be called using the Lua method invokation syntax.
Examples:
widget:setEnabled(true) widget:show()
Public and protected member functions whose c++ declaration
is marked with the Qt macro Q_INVOKABLE
can also be invoked
using the standard Lua syntax.
When a member function has the same name as a property, the property takes precedence. When overloaded member functions are exposed in this fashion, the QtLua library makes a best effort to determine which function should be called. It first narrows the choices using the number of parameters. When several options remain, it chooses one on the basis of the types of the parameters. Member function arguments with default values are handled by considering implicit overloaded functions.
It is always possible to work around these rules by selecting a particular member function using its signature.
widget['setEnabled(bool)'](widget, true)
Member functions exposes in this way are always invoked from the thread owning the Qt object. If the Lua interpreter runs in a different thread, a thread hopping operation is performed for the duration of the operation.
Argument types and return values are automatically converted.
Lua strings can be specified when a QByteArray
or a QString
are expected. Lua numbers can be specified
whenever numerical types are expected.
Inheritance ensures that all methods exposed
by a class are also exposed by its subclasses.
Methods exposed by the QObject
class,
such as deleteLater()
,
are inherited by all Qt object classes.