libFAUDES

Sections

Index

faudes::LuaFunctionDefinition Class Reference
[Lua Bindings PlugIn]

A LuaFunctionDefinition is derived from FaunctionDefinition to defines a faudes-function to be a luafaudes script. More...

#include <lbp_function.h>

List of all members.

Public Member Functions

 LuaFunctionDefinition (const std::string &name="")
 Constructor.
 LuaFunctionDefinition (const LuaFunctionDefinition &rSrc)
 Copy constructor.
virtual ~LuaFunctionDefinition (void)
 Destructor.
void Clear (void)
 Clear documentation-data, signature and script (keep prototype).
const std::string & LuaCode (void) const
 Get Lua code.
void LuaCode (const std::string &rCode)
 Set Lua code.
std::string SyntaxCheck (void)
 Syntax check lua code.

Protected Member Functions

virtual LuaFunctionDefinitionDoAssign (const LuaFunctionDefinition &rSrc)
 Std faudes type interface: assignment.
virtual bool DoEqual (const LuaFunctionDefinition &rOther) const
 Std faudes type interface: test equality.
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data of this object from TokenReader.
virtual void DoReadCore (TokenReader &rTr)
 Read configuration data of this object from TokenReader.
virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data of this object to TokenWriter.
virtual void DoWriteCore (TokenWriter &rTw) const
 Write configuration data of this object to TokenWriter.
virtual void Prototype (Function *pFunc)
 Assign prototype object.

Protected Attributes

LuaFunctionpLuaFunction
 Typed prototype instance.
std::string mLuaCode
 Lua code.
std::string mLuaFile
 Lua file.

Detailed Description

A LuaFunctionDefinition is derived from FaunctionDefinition to defines a faudes-function to be a luafaudes script.

Thus, it has the lua code as an additional member variable and uses a LuaFunction as a prototype object. In particular, LuaFunctionDefinitions are allways valid in the sense that hey have a prototype. The LuaFunction object implements DoTypeCheck and DoExecute to run the specifed lua code.

The token io format is demonstrated by the following example:

 <LuaFunctionDefinition>

 "LuaInteregrSum::LuaExtension"

 <TextDoc> "Returns the sum of two integer arguments." </TextDoc>
 <HtmlDoc> "integersum.html" </HtmlDoc>
 <Keywords> "luafunctions" "example" </Keywords>

 <VariantSignatures>
 <Signature>
 "Res=A+B"
 "ArgA"  "Integer"   +In+
 "ArgB"  "Integer"   +In+
 "Res"   "Integer"   +Out+
 </Signature>
 </VariantSignatures>
 
 <LuaCode> 
 __VERBATIM__

 -- Define my function
 function Res_A_B(a,b,res)
   print(string.format('Res_A_B(...): a=%d b=%d',a,b))
   res=a+b
   return a,b,res
 end

 __VERBATIM__
 </LuaCode>

 </LuaFunctionDefinition>

Alternatively to the embedded code, the luacode can be read from an external file, specified by a section LuaFile. (not implemented)

Restrictions and conventions:

  • Typechecking is done via the Cast() function of the faudes type interface. As a consequence, you may only use types that are registered with run-time-interface.
  • On execution, the LuaFunction instance has to locate the respective function in the supplied lua code. In order to allow for multiple variants, the convention is to have one lua function each with the name of the corresponding variant. Since variant names may contain funny characters, name matching is performed after replacing any sequence of non-alpha-numericals by "_". E.g. the variant "res=a+b" matches the lua function "res_a_b".
  • Since luafaudes has no concept of const references, it is the responsability of the script programer to respect parameter types +In+, +Out+ and +InOut+.
  • Integers, booleans ans strings are passed to Lua by value, any other parameters are passed by reference. To have a uniform interface, the convention is that the lua function must return all specified parameters.

Definition at line 102 of file lbp_function.h.


Constructor & Destructor Documentation

faudes::LuaFunctionDefinition::LuaFunctionDefinition ( const std::string &  name = ""  ) 

Constructor.

In contrast to the std FunctionDefinition, the default constructor sets up a valid lua function definition with a newly created LuaFunction as prototype. Of course, you will need to set the signatures and the lua code to obtain an operational function.

Definition at line 44 of file lbp_function.cpp.

faudes::LuaFunctionDefinition::LuaFunctionDefinition ( const LuaFunctionDefinition rSrc  ) 

Copy constructor.

Definition at line 54 of file lbp_function.cpp.

virtual faudes::LuaFunctionDefinition::~LuaFunctionDefinition ( void   )  [inline, virtual]

Destructor.

Definition at line 128 of file lbp_function.h.


Member Function Documentation

void faudes::LuaFunctionDefinition::Clear ( void   )  [virtual]

Clear documentation-data, signature and script (keep prototype).

Reimplemented from faudes::FunctionDefinition.

Definition at line 90 of file lbp_function.cpp.

LuaFunctionDefinition & faudes::LuaFunctionDefinition::DoAssign ( const LuaFunctionDefinition rSrc  )  [protected, virtual]

Std faudes type interface: assignment.

Parameters:
rSrc Source to copy from
Returns:
Reference to this object.

Definition at line 62 of file lbp_function.cpp.

bool faudes::LuaFunctionDefinition::DoEqual ( const LuaFunctionDefinition rOther  )  const [protected, virtual]

Std faudes type interface: test equality.

Parameters:
rOther Other object to compare with.
Returns:
True on match.

Definition at line 80 of file lbp_function.cpp.

void faudes::LuaFunctionDefinition::DoRead ( TokenReader rTr,
const std::string &  rLabel = "",
const Type pContext = 0 
) [protected, virtual]

Read configuration data of this object from TokenReader.

Actual reading is done by DoReadCore.

The section defaults to "LuaFunctionDefinition", context ignored.

Parameters:
rTr TokenReader to read from
rLabel Section to read
pContext Read context to provide contextual information (ignored)
Exceptions:
Exception 
  • Token mismatch (id 50, 51, 52)
  • IO error (id 1)

Reimplemented from faudes::FunctionDefinition.

Definition at line 157 of file lbp_function.cpp.

void faudes::LuaFunctionDefinition::DoReadCore ( TokenReader rTr  )  [protected, virtual]

Read configuration data of this object from TokenReader.

This method reads members only, it does not read the section.

Parameters:
rTr TokenReader to read from
Exceptions:
Exception 
  • Token mismatch (id 50, 51, 52)
  • IO error (id 1)

Reimplemented from faudes::FunctionDefinition.

Definition at line 172 of file lbp_function.cpp.

void faudes::LuaFunctionDefinition::DoWrite ( TokenWriter rTw,
const std::string &  rLabel = "",
const Type pContext = 0 
) const [protected, virtual]

Write configuration data of this object to TokenWriter.

The section defaults to "LuaFunctionDefinition", context ignored.

Parameters:
rTw Reference to TokenWriter
rLabel Label of section to write
pContext Write context to provide contextual information
Exceptions:
Exception 
  • IO errors (id 2)

Reimplemented from faudes::FunctionDefinition.

Definition at line 199 of file lbp_function.cpp.

void faudes::LuaFunctionDefinition::DoWriteCore ( TokenWriter rTw  )  const [protected, virtual]

Write configuration data of this object to TokenWriter.

This method writes plain member data, the section lables are not written.

Parameters:
rTw Reference to TokenWriter
Exceptions:
Exception 
  • IO errors (id 2)

Reimplemented from faudes::FunctionDefinition.

Definition at line 208 of file lbp_function.cpp.

void faudes::LuaFunctionDefinition::LuaCode ( const std::string &  rCode  ) 

Set Lua code.

Parameters:
rCode Lua code as std string

Definition at line 113 of file lbp_function.cpp.

const std::string & faudes::LuaFunctionDefinition::LuaCode ( void   )  const

Get Lua code.

Returns:
Lua code as std string

Definition at line 108 of file lbp_function.cpp.

void faudes::LuaFunctionDefinition::Prototype ( Function pFunc  )  [protected, virtual]

Assign prototype object.

Parameters:
pFunc Function instance

Reimplemented from faudes::FunctionDefinition.

Definition at line 100 of file lbp_function.cpp.

std::string faudes::LuaFunctionDefinition::SyntaxCheck ( void   ) 

Syntax check lua code.

This routine instantiates a LuaFunction from this function definition and does all it needs to run the script, except to invoke the any of the variant functions. The reasoning is, that the script may hang and, thus, never return. Errors are indicated by an exception.

Returns:
Error message as string, or empty string on success

Definition at line 119 of file lbp_function.cpp.


Member Data Documentation

std::string faudes::LuaFunctionDefinition::mLuaCode [protected]

Lua code.

Definition at line 265 of file lbp_function.h.

std::string faudes::LuaFunctionDefinition::mLuaFile [protected]

Lua file.

Definition at line 268 of file lbp_function.h.

Typed prototype instance.

Definition at line 262 of file lbp_function.h.


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

libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3