|
|
||||||
|
Public Member Functions |
Static Public Member Functions |
Protected Member Functions |
Protected Attributes |
List of all members
faudes::LuaFunctionDefinition Class Reference Detailed DescriptionA LuaFunctionDefinition is derived from FunctionDefinition to define a faudes-function by a Lua script. 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. Thus, a LuaFunction can be tranparently accessed via the run-time interface and bahves like any other registered faudes function. Alternatively, you can use the Install() method to install a LuaFunctionDefinition to a LuaState. Then, the function can be accessed by the Lua interpreter. Install() will generate code to dispatch the function variants with the same semantics as the SWIG generated interface for other faudes functions. Again, integeration is transparent from the perspective of the Lua interpreter. The token io format is demonstrated by the following example: <LuaFunctionDefinition name="LuaExtension::LargeGenerator">
Construct a generator by random.
<VariantSignatures>
<Signature name="LargeGen(#Q,#Sigma,GRes)">
<Parameter name="SizeQ" ftype="Integer" access="In"/>
<Parameter name="SizeSigma" ftype="Integer" access="In"/>
<Parameter name="Res" ftype="Generator" access="Out" />
</Signature>
</VariantSignatures>
<LuaCode>
<[CDATA[
-- Extension reports on loading
print('loading luaextension "LargeGenerator"')
-- Define my function (mangled version of variant name)
function faudes.LargeGen_Q_Sigma_GRes(qn,sn,gen)
-- Function reports on execution
print(string.format('LargeGen(...): qn=%d sn=%d',qn,sn))
-- Exeution code
gen:Clear()
for i=1,qn do
gen:InsState(i)
end
for i=1,sn do
gen:InsEvent(string.format('ev_%d',i))
end
-- Done
return
-- End of function definition
end
-- Extension reports on loading
print('loading luaextension: done')
]]>
</LuaCode>
const std::string & Keywords(void) const Definition: cfl_types.cpp:401 void Clear(void) Clear documentation-data, signature and script (keep prototype) Definition: lbp_function.cpp:226 Restrictions and conventions:
Definition at line 140 of file lbp_function.h.
Constructor & Destructor Documentation◆ LuaFunctionDefinition() [1/2]
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 180 of file lbp_function.cpp. ◆ LuaFunctionDefinition() [2/2]
Copy constructor. Definition at line 191 of file lbp_function.cpp. ◆ ~LuaFunctionDefinition()
Destructor. Definition at line 166 of file lbp_function.h. Member Function Documentation◆ Clear()
Clear documentation-data, signature and script (keep prototype) Reimplemented from faudes::FunctionDefinition. Definition at line 226 of file lbp_function.cpp. ◆ DefaultL() [1/2]
Set default lua state. Sets the default lua state on which functions that refer to this function definition will use for execution. If set to NULL (e.g. on consruction), the global state is used. However, the function object itself may overwrite the default.
Definition at line 260 of file lbp_function.cpp. ◆ DefaultL() [2/2]
◆ DoAssign()
Std faudes type interface: assignment.
Definition at line 200 of file lbp_function.cpp. ◆ DoEqual()
Std faudes type interface: test equality.
Definition at line 216 of file lbp_function.cpp. ◆ DoRead()
Read configuration data of this object from TokenReader. Actual reading is done by DoReadCore. The section defaults to "LuaFunctionDefinition", context ignored.
Reimplemented from faudes::FunctionDefinition. ◆ DoReadCore()
Read configuration data of this object from TokenReader. This method reads members only, it does not read the section.
Reimplemented from faudes::FunctionDefinition. ◆ DoWrite()
Write configuration data of this object to TokenWriter. The section defaults to "LuaFunctionDefinition", context ignored.
Reimplemented from faudes::FunctionDefinition. ◆ DoWriteCore()
Write configuration data of this object to TokenWriter. This method writes plain member data, the section lables are not written.
Reimplemented from faudes::FunctionDefinition. ◆ Evaluate()
Evaluate lua code. This routine evaluates the LuaCode literally. This method is used to execute LuaCode that is not part of any particular variant. To execute a particular variant, instantiate a LuaFunction and invoke Execute(). If you pass NULL as destination state, the global state will be used.
Definition at line 303 of file lbp_function.cpp. ◆ Install() [1/2]
Install this function to a Lua state. Alternative signature for applications that do not use the the LuaState wrapper class. See also Install(LuaState*).
Definition at line 326 of file lbp_function.cpp. ◆ Install() [2/2]
Install this function to a Lua state. This routine installs the Lua code of this function definition to the table "faudes" of the specified Lua state. It also constructs a wrapper function to dispatch signatures and palces this in the table "faudes". Effectively, the resulting Lua state is prepared to execute the Lua function with the same semantics as used for SWIG generated wrappers of C++ functions. If you pass NULL as destination state, the global state will be used.
Definition at line 320 of file lbp_function.cpp. ◆ LuaCode() [1/2]
Set Lua code.
Definition at line 249 of file lbp_function.cpp. ◆ LuaCode() [2/2]
◆ Prototype()
Assign prototype object.
Reimplemented from faudes::FunctionDefinition. Definition at line 236 of file lbp_function.cpp. ◆ Register()
◆ SyntaxCheck()
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 returned as an error string.
Definition at line 265 of file lbp_function.cpp. Member Data Documentation◆ mLuaCode
Lua code. Definition at line 390 of file lbp_function.h. ◆ mLuaFile
Lua file. Definition at line 393 of file lbp_function.h. ◆ pDefaultL
Default lua state. Definition at line 396 of file lbp_function.h. ◆ pLuaFunction
Typed prototype instance. Definition at line 387 of file lbp_function.h. The documentation for this class was generated from the following files: libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen |