Function class reference
[Base module]

Declaration  

#include <QtLua/Function>

namespace QtLua {
class Function;
};

This class is a member of the QtLua namespace.

This abstract class is declared in QtLua/qtluafunction.hh source file, line 66.

This abstract class contains pure virtuals.

Description  

This class is a convenient base class for exposing functions like objects to lua scripts. It's based on the UserData class and is handled by lua as an userdata value with redefined call operation.

Basic argument checking can be done using the UserData::meta_call_check_args function. More argument checking and conversion can be performed with the Function::get_arg family of functions. See Qt/Lua types conversion for supported types and conversion operations.

The QTLUA_FUNCTION macro is provided to easily declare a Function sub class:

// code from examples/cpp/userdata/function.cc:25

QTLUA_FUNCTION(foo, "This function returns \"test\"",
"usage: foo()")
{
return QtLua::Value(ls, "test");
}

Function objects can be exposed as a lua values:

// code from examples/cpp/userdata/function.cc:59

QtLua::State state;

static QtLua_Function_foo foo;

QtLua::Value f(&state, foo);

A convenience constructor is provided to register functions as global lua variables:

Functions can also be registered on a Plugin objects.

Members  

Inherited members  

Types  

Functions  

Protected function  

  • virtual ValueBase::List meta_call(State *ls, const ValueBase::List &args) = 0;

Private functions  

Static functions  

  • static template X get_arg(const ValueBase::List &args, int n, const X &default_)
  • static template X get_arg(const ValueBase::List &args, int n)
  • static template X * get_arg_cl(const ValueBase::List &args, int n)
  • static template X * get_arg_qobject(const ValueBase::List &args, int n)
  • static template Ref<X> get_arg_ud(const ValueBase::List &args, int n)

Macros  

Members detail  

#define QTLUA_FUNCTION(name, description, help)  

This macro is declared in QtLua/qtluafunction.hh source file, line 126.

This macro declares a new a Function class named QtLua_Function_name with functions to handle description, help and function call. User provided code is used for reimplementation of the UserData::meta_call function.

// code from examples/cpp/userdata/function.cc:25

QTLUA_FUNCTION(foo, "This function returns \"test\"",
"usage: foo()")
{
return QtLua::Value(ls, "test");
}

This macro expands to:

QTLUA_FUNCTION_DECL(name)
QTLUA_FUNCTION_BODY(name, description, help)

#define QTLUA_FUNCTION_BODY(name, description, help)  

This macro is declared in QtLua/qtluafunction.hh source file, line 100.

This macro contains functions definition for QTLUA_FUNCTION.

This macro expands to:

QtLua::String QtLua_Function_##name
::get_description() const { return description; }

QtLua::String QtLua_Function_##name
::get_help() const { return help; }

QtLua_Function_##name
::QtLua_Function_##name() { }

QtLua_Function_##name
::QtLua_Function_##name(QtLua::State *ls, const QtLua::String &path)
{ register_(ls, path); }

QtLua::Value::List QtLua_Function_##name
::meta_call(QtLua::State *ls, const QtLua::Value::List &args)

#define QTLUA_FUNCTION_DECL(name)  

This macro is declared in QtLua/qtluafunction.hh source file, line 86.

This macro contains class declaration for QTLUA_FUNCTION.

This macro expands to:

class QtLua_Function_##name : public QtLua::Function
{
QtLua::Value::List meta_call(QtLua::State *ls, const QtLua::Value::List &args);
QtLua::String get_description() const;
QtLua::String get_help() const;
public:
QtLua_Function_##name();
QtLua_Function_##name(QtLua::State *ls, const QtLua::String &path);
};

#define QTLUA_FUNCTION_REGISTER(state, prefix, name)  

This macro is declared in QtLua/qtluafunction.hh source file, line 132.

This macro declares and registers a Function object on a QtLua State object as a global variable.

This macro expands to:

static QtLua_Function_##name name(state, prefix #name)

#define QTLUA_FUNCTION_REGISTER2(state, path, name)  

This macro is declared in QtLua/qtluafunction.hh source file, line 137.

This macro declares and registers a Function object on a QtLua State object as a global variable.

This macro expands to:

static QtLua_Function_##name name(state, path)

virtual void completion_patch(String &path, String &entry, int &offset)  

This virtual function is declared in QtLua/qtluafunction.hh source file, line 241.

This member access is private.

This virtual function overrides the completion_patch virtual function defined in the UserData base class.

Documentation inherited from base class:

This function may be reimplemented to further modify completion result on console line when completed to a UserData value. This is usefull to append a dot or a pair of brackets access operator to the userdata value name for instance.

Parameters list:

  • path: Completion result tables path to userdata value.
  • entry: Completion result userdata name. May append to this string directly.
  • offset: Cursor offset. May be decreased to place cursor between inserted brackets for instance.

typedef Ref<const Function, Function> const_ptr  

This typedef is declared in QTLUA_REFTYPE function like macro expansion, line 3 in QtLua/qtluafunction.hh source file, line 68.

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

static template <typename X> X get_arg(const ValueBase::List &args, int n, const X &default_)  

This template function is declared in QtLua/qtluafunction.hh source file, line 168.

This function may be called from the Function::meta_call function to perform lua to C++ argument conversion and checking.

It checks if the argument is available and tries to convert argument to X type and throw if conversion fails. A default value is returned if no argument exists at specified index.

Parameters list:

  • args: arguments list
  • n: argument index in list
  • default_: default value to return if no argument available

The return value is C++ converted value

Example:

// code from examples/cpp/userdata/function.cc:25

QTLUA_FUNCTION(foo, "This function returns \"test\"",
"usage: foo()")
{
QtLua::String a = get_arg<QtLua::String>(args, 0);
int b = get_arg<int>(args, 1, 42);

See also Qt/Lua types conversion section and Function::get_arg function.

static template <typename X> X get_arg(const ValueBase::List &args, int n)  

This template function is declared in QtLua/qtluafunction.hh source file, line 180.

This function does the same as the Function::get_arg function but throws if the argument is not available instead of returning a default value.

See also Function::get_arg function and Function::get_arg_ud function.

static template <typename X> X * get_arg_cl(const ValueBase::List &args, int n)  

This template function is declared in QtLua/qtluafunction.hh source file, line 217.

This function may be called from the Function::meta_call function to perform lua to C++ argument conversion and checking.

It checks if the argument is available and if it is an UserData object and tries to dynamic_cast it to the specified class. This function throws an exception if the result is null.

Parameters list:

  • args: arguments list
  • n: argument index in list

The return value is pointer to X type.

See also Qt/Lua types conversion section and Function::get_arg function.

static template <typename X> X * get_arg_qobject(const ValueBase::List &args, int n)  

This template function is declared in QtLua/qtluafunction.hh source file, line 235.

This function may be called from the Function::meta_call function to perform lua to C++ argument conversion and checking.

It checks if the argument is available and if it is a QObject wrapper and tries to cast to the requested QObject based class using the ValueBase::to_qobject_cast function.

Parameters list:

  • args: arguments list
  • n: argument index in list

The return value is pointer to X type.

See also Qt/Lua types conversion section and Function::get_arg function.

static template <typename X> Ref<X> get_arg_ud(const ValueBase::List &args, int n)  

This template function is declared in QtLua/qtluafunction.hh source file, line 198.

This function may be called from the Function::meta_call function to perform lua to C++ argument conversion and checking.

It checks if the argument is available and if it is an UserData object and tries to cast it using the ValueBase::to_userdata_cast function.

Parameters list:

  • args: arguments list
  • n: argument index in list

The return value is Ref pointer to X type.

See also Qt/Lua types conversion section and Function::get_arg function.

virtual String get_description() const  

This virtual function is declared in QtLua/qtluafunction.hh source file, line 78.

This function may be reimplemented to return a short description of the function.

virtual String get_help() const  

This virtual function is declared in QtLua/qtluafunction.hh source file, line 82.

This function may be reimplemented to return a function usage help string.

virtual String get_type_name() const  

This virtual function is declared in QtLua/qtluafunction.hh source file, line 239.

This member access is private.

This virtual function overrides the get_type_name virtual function defined in the UserData base class.

Documentation inherited from base class:

This function returns an object type name. The default implementation returns the C++ object type name. This is used for error messages and pretty printing.

The return value is Pretty print object type.

virtual String get_value_str() const  

This virtual function is declared in QtLua/qtluafunction.hh source file, line 238.

This member access is private.

This virtual function overrides the get_value_str virtual function defined in the UserData base class.

Documentation inherited from base class:

This function returns an string value describing object value or content. The default implementation returns an hexadecimal object pointer. This is used for mainly for pretty printing.

virtual ValueBase::List meta_call(State *ls, const ValueBase::List &args) = 0;  

This pure virtual function is declared in QtLua/qtluafunction.hh source file, line 143.

This member access is protected.

This pure virtual function shadows the meta_call virtual function defined in the UserData base class.

Documentation inherited from base class:

This function is called when a function invokation operation is performed 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::OpCall as supported.

Parameters list:

  • args: List of passed arguments.

The return value is List of returned values.

typedef Ref<Function, Function> ptr  

This typedef is declared in QTLUA_REFTYPE function like macro expansion, line 5 in QtLua/qtluafunction.hh source file, line 68.

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

virtual bool support(ValueBase::Operation c) const  

This virtual function is declared in QtLua/qtluafunction.hh source file, line 240.

This member access is private.

This virtual function overrides the support virtual function defined in the UserData base class.

Documentation inherited from base class:

Check given operation support.

See also ValueBase::support function.

void register_(State *ls, const String &path)  

This function is for internal use only.

This function is declared in QtLua/qtluafunction.hh source file, line 71.

void register_(Plugin &plugin, const String &name)  

This function is for internal use only.

This function is declared in QtLua/qtluafunction.hh source file, line 74.

See also Plugin class.

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 16:23:03 2013 using MkDoc