Detailed Description

A LuaFunction is a faudes-function that executes a luafaudes script.

LuaFunction is derived from Function and implements the DoTypeCheck and DoExecute interface to run the lua code as supplied by the corresponding function defintion. Thus, it is considered an error to set the function definition to an object that does not cast to a LuaFunctionDefinition.

Definition at line 677 of file lbp_function.h.

#include <lbp_function.h>

Public Member Functions

 LuaFunction (const LuaFunctionDefinition *fdef)
 Constructor. More...
 
 ~LuaFunction (void)
 Destructor. More...
 
virtual LuaFunctionNew () const
 Construct on heap. More...
 
void Definition (const FunctionDefinition *fdef)
 Set function definition. More...
 
const LuaFunctionDefinitionDefinition (void) const
 Get function definition. More...
 
void SyntaxCheck (void)
 Syntax check lua code. More...
 
void Evaluate (void)
 Evaluate lua code. More...
 
void L (LuaState *l)
 Set lua state. More...
 
LuaStateL (void)
 Get default lua state. More...
 
- Public Member Functions inherited from faudes::Function
 Function (const FunctionDefinition *fdef)
 Constructor For the function to be operational, a valid reference to the corresponding FunctionDefinition is required. More...
 
 ~Function ()
 Destructor. More...
 
const FunctionDefinitionDefinition (void) const
 Get function definition. More...
 
int VariantsSize (void) const
 Return number of variants. More...
 
void Variant (int n)
 Set signature from function definition. More...
 
void Variant (const std::string &rVariantName)
 Set signature from function definition. More...
 
const SignatureVariant (void) const
 Return pointer to assigned faudes::Signature. More...
 
int ParamsSize (void) const
 Return number of parameters with current signature. More...
 
void ParamValue (int n, Type *param)
 Set parameter at certain position. More...
 
TypeParamValue (int n) const
 Get parameter value. More...
 
void AllocateValues (void)
 Construct parameter values. More...
 
void AllocateValue (int i)
 
void FreeValues (void)
 Destruct parameter values. More...
 
bool TypeCheck (int n)
 Perform a type check one parameter value. More...
 
bool TypeCheck (void)
 Perform a type check on the list of current parameter values. More...
 
void Execute (void)
 Perform operation. More...
 
- Public Member Functions inherited from faudes::Type
 Type (void)
 Constructor. More...
 
 Type (const Type &rType)
 Copy constructor. More...
 
virtual ~Type (void)
 Destructor. More...
 
virtual TypeCopy (void) const
 Construct on heap. More...
 
virtual const TypeCast (const Type *pOther) const
 Cast other object to this type. More...
 
virtual void Clear (void)
 Clear configuration data. More...
 
virtual TypeAssign (const Type &rSrc)
 Assign configuration data from other object. More...
 
virtual Typeoperator= (const Type &rSrc)
 Assign configurationdata from other object. More...
 
virtual bool Equal (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual bool operator== (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual bool operator!= (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual void Name (const std::string &rName)
 Set the objects's name. More...
 
virtual const std::string & Name (void) const
 Get objects's name. More...
 
virtual const std::string & TypeName (void) const
 Get objects's type name. More...
 
void Write (const Type *pContext=0) const
 Write configuration data to console. More...
 
void Write (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 Write configuration data to a file. More...
 
void Write (const std::string &pFileName, std::ios::openmode openmode) const
 Write configuration data to a file. More...
 
void Write (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to TokenWriter. More...
 
virtual void XWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to an XML file. More...
 
void XWrite (const Type *pContext=0) const
 Write configuration data in XML format to concole Note: this write function uses the virtual function DoXWrite(), to be reimplemented by derived classes. More...
 
void XWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in XML format to TokenWriter. More...
 
std::string ToString (const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to a string. More...
 
std::string ToText (const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to a formated string. More...
 
void DWrite (const Type *pContext=0) const
 Write configuration data to console, debugging format. More...
 
void DWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 Write configuration data to a file, debugging format. More...
 
void DWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in debug format to TokenWriter. More...
 
void SWrite (TokenWriter &rTw) const
 Write statistics comment to TokenWriter. More...
 
void SWrite (void) const
 Write statistics comment to console. More...
 
std::string ToSText (void) const
 Write statistics to a string. More...
 
void Read (const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from file with label specified. More...
 
void FromString (const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from a string. More...
 
void Read (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from TokenReader with label sepcified. More...
 

Protected Member Functions

virtual void DoVariant (int n)
 
virtual bool DoTypeCheck (int n)
 Method to test the type of an assigned parameter with the specified faudes::Signature (i.e. More...
 
virtual void DoExecute ()
 Executes code as supplied by FunctionDefinition. More...
 
virtual void DoExecuteA ()
 Execute stages. More...
 
virtual void DoExecuteB ()
 Execute stages. More...
 
virtual void DoExecuteC ()
 Execute stages. More...
 
virtual void DoExecuteD ()
 Execute stages. More...
 
virtual void DoExecuteE ()
 Execute stages. More...
 
- Protected Member Functions inherited from faudes::Function
template<class T >
bool DoTypeCast (int n, T *&rTypedRef)
 Helper: generate typed reference for parameter. More...
 
void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write function-data (typeid-name of arguments) to TokenWriter. More...
 
- Protected Member Functions inherited from faudes::Type
void DoAssign (const Type &rSrc)
 Assign configuration data from other object. More...
 
bool DoEqual (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data of this object from TokenReader. More...
 
virtual void DoXWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data of this object to TokenWriter in XML format. More...
 
virtual void DoDWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in debugging format to TokenWriter. More...
 
virtual void DoSWrite (TokenWriter &rTw) const
 Write statistical data as a comment to TokenWriter. More...
 
virtual const TypeDefinitionTypeDefinitionp (void) const
 Get objects's type definition. More...
 
virtual Token XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const
 

Protected Attributes

const LuaFunctionDefinitionpLuaFuncDef
 Typed reference to definition. More...
 
LuaStatepL
 State of Lua interpreter. More...
 
lua_State * pLL
 
int mFtable
 
int mEntryStack
 
void * mFType
 
std::vector< bool > mLReturn
 
std::vector< bool > mLParameter
 
int mLReturnCount
 
int mLParameterCount
 
- Protected Attributes inherited from faudes::Function
const FunctionDefinitionpFuncDef
 corresponding function definition More...
 
int mVariantIndex
 current variant aka signature as index w.r.t. More...
 
std::vector< Type * > mParameterValues
 Vector of arguments. More...
 

Constructor & Destructor Documentation

◆ LuaFunction()

faudes::LuaFunction::LuaFunction ( const LuaFunctionDefinition fdef)

Constructor.

For the function to be operational, a valid reference to the corresponding LuaFunctionDefinition is required. The only exception is the prototype function object used in the LuaFunctionDefinition itself.

◆ ~LuaFunction()

faudes::LuaFunction::~LuaFunction ( void  )
inline

Destructor.

Definition at line 689 of file lbp_function.h.

Member Function Documentation

◆ Definition() [1/2]

void faudes::LuaFunction::Definition ( const FunctionDefinition fdef)
virtual

Set function definition.

Normally, functions are provided with a function definition on construction. The only exception are prototype objects used in function definitions themselfs and in the function registry.

Parameters
fdefFunction definition to set.

Reimplemented from faudes::Function.

◆ Definition() [2/2]

const LuaFunctionDefinition* faudes::LuaFunction::Definition ( void  ) const

Get function definition.

Returns
Function definition used by this function.

◆ DoExecute()

virtual void faudes::LuaFunction::DoExecute ( )
protectedvirtual

Executes code as supplied by FunctionDefinition.

Exceptions
Exception
  • Exception during lua setup (id 49)
  • Any exception during execution of script

Implements faudes::Function.

◆ DoExecuteA()

virtual void faudes::LuaFunction::DoExecuteA ( )
protectedvirtual

Execute stages.

Exceptions
Exception

◆ DoExecuteB()

virtual void faudes::LuaFunction::DoExecuteB ( )
protectedvirtual

Execute stages.

Exceptions
Exception

◆ DoExecuteC()

virtual void faudes::LuaFunction::DoExecuteC ( )
protectedvirtual

Execute stages.

Exceptions
Exception
  • Exception during lua setup (id 49)
  • Any exception during execution of script

◆ DoExecuteD()

virtual void faudes::LuaFunction::DoExecuteD ( )
protectedvirtual

Execute stages.

Exceptions
Exception

◆ DoExecuteE()

virtual void faudes::LuaFunction::DoExecuteE ( )
protectedvirtual

Execute stages.

Exceptions
Exception

◆ DoTypeCheck()

virtual bool faudes::LuaFunction::DoTypeCheck ( int  n)
protectedvirtual

Method to test the type of an assigned parameter with the specified faudes::Signature (i.e.

their TypeDefinition label).

Note: this method is called by Function::Execute() before actual function execution via DoExecute(). It may be used to perform a dynamic cast in preparation of DoExecute(). The latter is only called, if all types match.

Parameters
nPosition of parameter to check
Returns
True if type matches signature.
Exceptions
Exception

Implements faudes::Function.

◆ DoVariant()

virtual void faudes::LuaFunction::DoVariant ( int  n)
protectedvirtual

Reimplemented from faudes::Function.

◆ Evaluate()

void faudes::LuaFunction::Evaluate ( void  )

Evaluate lua code.

This routine avaluates the associated Lua code literally, i.e. no arguments are passed, no specific function is invoked. See also Execute().

Exceptions
Exception
  • Error in Lua script (id 49)

◆ L() [1/2]

void faudes::LuaFunction::L ( LuaState l)

Set lua state.

Sets the lua state which this function will use for execution. If set to NULL (e.g. on consruction), the function definition's default state will be used. If this is not set either, the global state is used.

Parameters
lLua state

◆ L() [2/2]

LuaState* faudes::LuaFunction::L ( void  )

Get default lua state.

Returns
Lua state

◆ New()

virtual LuaFunction* faudes::LuaFunction::New ( ) const
virtual

Construct on heap.

Create a new instance of this function class and return pointer. The new instance will use the same function definition as this instance.

Returns
Pointer to faudes::Function instance.

Implements faudes::Function.

◆ SyntaxCheck()

void faudes::LuaFunction::SyntaxCheck ( void  )

Syntax check lua code.

This routine does all it needs to run the script, except to invoke the specified function. The reasoning is, that the script may hang and, thus, never return. A consequence is, that you must set a variant and you must supply parameter values befor checking. You may use AllocateValues() and FreeValues() for this purpose. Errors are indicated by an exception.

Note that the LuaFunctionDefinition provides a convenience wrapper that runs the check on all variants and cares about value allocation.

Exceptions
Exception
  • No such variant (id 47)
  • Error in Lua script (id 49)

Member Data Documentation

◆ mEntryStack

int faudes::LuaFunction::mEntryStack
protected

Definition at line 875 of file lbp_function.h.

◆ mFtable

int faudes::LuaFunction::mFtable
protected

Definition at line 874 of file lbp_function.h.

◆ mFType

void* faudes::LuaFunction::mFType
protected

Definition at line 876 of file lbp_function.h.

◆ mLParameter

std::vector<bool> faudes::LuaFunction::mLParameter
protected

Definition at line 878 of file lbp_function.h.

◆ mLParameterCount

int faudes::LuaFunction::mLParameterCount
protected

Definition at line 880 of file lbp_function.h.

◆ mLReturn

std::vector<bool> faudes::LuaFunction::mLReturn
protected

Definition at line 877 of file lbp_function.h.

◆ mLReturnCount

int faudes::LuaFunction::mLReturnCount
protected

Definition at line 879 of file lbp_function.h.

◆ pL

LuaState* faudes::LuaFunction::pL
protected

State of Lua interpreter.

Definition at line 872 of file lbp_function.h.

◆ pLL

lua_State* faudes::LuaFunction::pLL
protected

Definition at line 873 of file lbp_function.h.

◆ pLuaFuncDef

const LuaFunctionDefinition* faudes::LuaFunction::pLuaFuncDef
protected

Typed reference to definition.

Definition at line 869 of file lbp_function.h.


The documentation for this class was generated from the following file:

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen