lbp_function.hGo to the documentation of this file.00001 /** @file lbp_function.h luafaudes class to run scripts as rti functions */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2010 Thomas Moor 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00020 00021 00022 #ifndef FAUDES_LBPFUNCTION_H 00023 #define FAUDES_LBPFUNCTION_H 00024 00025 #include "corefaudes.h" 00026 00027 // forward 00028 struct lua_State; 00029 00030 namespace faudes{ 00031 00032 // forward 00033 class LuaFunction; 00034 class LuaState; 00035 00036 /** 00037 * A LuaFunctionDefinition is derived from FunctionDefinition to 00038 * define a faudes-function by a Lua script. It has 00039 * the Lua code as an additional member variable and uses a LuaFunction as a 00040 * prototype object. In particular, LuaFunctionDefinitions are allways 00041 * valid in the sense that hey have a prototype. The LuaFunction object 00042 * implements DoTypeCheck and DoExecute to run the specifed Lua code. 00043 * Thus, a LuaFunction can be tranparently accessed via the run-time interface 00044 * and bahves like any other registered faudes function. 00045 * 00046 * Alternatively, 00047 * you can use the Install() method to install a LuaFunctionDefinition to 00048 * a LuaState. Then, the function can be accessed by the Lua interpreter. 00049 * Install() will generate code to dispatch the function variants with the 00050 * same semantics as the SWIG generated interface for other faudes functions. 00051 * Again, integeration is transparent from the perspective of the Lua interpreter. 00052 * 00053 * 00054 * The token io format is demonstrated by the 00055 * following example: 00056 * 00057 * @code 00058 * <LuaFunctionDefinition name="LuaExtension::LargeGenerator"> 00059 * 00060 * <Documentation> 00061 * Construct a generator by random. 00062 * </Documentation> 00063 * <Keywords> "luaextension" "example" </Keywords> 00064 * 00065 * <VariantSignatures> 00066 * <Signature name="LargeGen(#Q,#Sigma,GRes)"> 00067 * <Parameter name="SizeQ" ftype="Integer" access="In"/> 00068 * <Parameter name="SizeSigma" ftype="Integer" access="In"/> 00069 * <Parameter name="Res" ftype="Generator" access="Out" /> 00070 * </Signature> 00071 * </VariantSignatures> 00072 * 00073 * <LuaCode> 00074 * <[CDATA[ 00075 * 00076 * -- Extension reports on loading 00077 * print('loading luaextension "LargeGenerator"') 00078 * 00079 * -- Define my function (mangled version of variant name) 00080 * function faudes.LargeGen_Q_Sigma_GRes(qn,sn,gen) 00081 * 00082 * -- Function reports on execution 00083 * print(string.format('LargeGen(...): qn=%d sn=%d',qn,sn)) 00084 * 00085 * -- Exeution code 00086 * gen:Clear() 00087 * for i=1,qn do 00088 * gen:InsState(i) 00089 * end 00090 * for i=1,sn do 00091 * gen:InsEvent(string.format('ev_%d',i)) 00092 * end 00093 * 00094 * -- Done 00095 * return 00096 * 00097 * -- End of function definition 00098 * end 00099 * 00100 * -- Extension reports on loading 00101 * print('loading luaextension: done') 00102 * 00103 * ]]> 00104 * </LuaCode> 00105 * 00106 * </LuaFunctionDefinition> 00107 * @endcode 00108 * 00109 * Restrictions and conventions: 00110 * - Type-checking is done via the Cast() function of the faudes Type interface. As a 00111 * consequence, you may only use types that are registered with the run-time-interface. 00112 * - On execution, the LuaFunction instance has to locate the respective function 00113 * in the supplied lua code. In order to allow for multiple variants, the convention is 00114 * to have one lua function each with the name of the corresponding variant. Since 00115 * variant names may contain funny characters, name matching is performed after 00116 * so called mangeling: any sequence of non-alpha-numerics is replaced by a single "_", 00117 * a trailing "_" is dropped. E.g. the variant <tt>res=a+b</tt> matches the Lua function <tt>res_a_b</tt>. 00118 * - Parameters other than elementary (integer, boolean and string) are passed to 00119 * the Lua function by reference. However, Lua will consistently interpret the reference itself 00120 * as a parameter value. Thus, to assign a value to an <tt>access="Out"</tt> or <tt>access="InOut"</tt> 00121 * parameter, you must use the assigment memberfunction Assign (as opposed to the assignment operator "="). 00122 * - Elementary types (i.e. integers, booleans and strings) are passed to the Lua function by value. 00123 * Thus, it would be pointless to have an elementary typed parameter with access attribute other than 00124 * <tt>access="In"</tt>. In order to implement elementary typed return values, the respective 00125 * Lua function must return the corresponding values by an approriate return statement. The signature 00126 * should indicate this by the attribute <tt>creturn="true"</tt>. The current implementation 00127 * will automatically imply <tt>creturn="true"</tt> for any <tt>access="Out"</tt> or 00128 * <tt>access="InOut"</tt>. 00129 * - Since luafaudes has no concept of const references, it is the responsability of the 00130 * script programer to respect parameter <tt>access</tt> attributes. 00131 * - When using Install() to install the function to a LuaState, a single wrapper function will be 00132 * defined to dispatch variants. By convention, this function is located in <tt>faudes.name_of_fdef</tt>, 00133 * where <tt>name_of_fdef</tt> is the name of the respective LuaFunctionDefinition. 00134 * 00135 * 00136 * 00137 * @ingroup LuabindingsPlugin 00138 */ 00139 00140 class LuaFunctionDefinition : public FunctionDefinition { 00141 00142 // faudes type 00143 FAUDES_TYPE_DECLARATION(LuaFunctionDefinition,LuaFunctionDefinition,FunctionDefinition) 00144 00145 public: 00146 00147 /** 00148 * Constructor. 00149 * 00150 * In contrast to the std FunctionDefinition, the default constructor 00151 * sets up a valid lua function definition with a newly created LuaFunction 00152 * as prototype. 00153 * Of course, you will need to set the signatures and the lua code 00154 * to obtain an operational function. 00155 */ 00156 LuaFunctionDefinition(const std::string& name=""); 00157 00158 /** 00159 * Copy constructor 00160 */ 00161 LuaFunctionDefinition(const LuaFunctionDefinition& rSrc); 00162 00163 /** 00164 * Destructor 00165 */ 00166 virtual ~LuaFunctionDefinition(void){}; 00167 00168 00169 /** 00170 * Clear documentation-data, signature and script (keep prototype) 00171 */ 00172 void Clear(void); 00173 00174 /** 00175 * Get Lua code 00176 * 00177 * @return 00178 * Lua code as std string 00179 */ 00180 const std::string& LuaCode(void) const; 00181 00182 /** 00183 * Set Lua code 00184 * 00185 * @param rCode 00186 * Lua code as std string 00187 */ 00188 void LuaCode(const std::string& rCode); 00189 00190 /** 00191 * Set default lua state. 00192 * 00193 * Sets the default lua state on which functions that refer to 00194 * this function definition will use for execution. 00195 * If set to NULL (e.g. on consruction), the 00196 * global state is used. However, the function object 00197 * itself may overwrite the default. 00198 * 00199 * @param pL 00200 * Lua state 00201 */ 00202 void DefaultL(LuaState* pL); 00203 00204 /** 00205 * Get default lua state. 00206 * 00207 * @return 00208 * Lua state 00209 */ 00210 LuaState* DefaultL(void) const; 00211 00212 /** 00213 * Syntax check lua code. 00214 * 00215 * This routine instantiates a LuaFunction from this function definition 00216 * and does all it needs to run the script, except to invoke the any of the 00217 * variant functions. The reasoning is, that the script may hang and, thus, 00218 * never return. Errors are indicated returned as an error string. 00219 * 00220 * @return 00221 * Error message as string, or empty string on success 00222 */ 00223 std::string SyntaxCheck(void); 00224 00225 /** 00226 * Evaluate lua code. 00227 * 00228 * This routine evaluates the LuaCode literally. This method is used to execute 00229 * LuaCode that is not part of any particular variant. To execute a 00230 * particular variant, instantiate a LuaFunction and invoke Execute(). 00231 * 00232 * If you pass NULL as destination state, the global state will be used. 00233 * 00234 * @param pL 00235 * Reference to the Lua state 00236 * @return 00237 * Error message as string, or empty string on success 00238 */ 00239 std::string Evaluate(LuaState* pL=NULL); 00240 00241 /** 00242 * Install this function to a Lua state 00243 * 00244 * This routine installs the Lua code of this function 00245 * definition to the table "faudes" of the specified Lua state. 00246 * It also constructs a wrapper function 00247 * to dispatch signatures and palces this in the table "faudes". 00248 * Effectively, the resulting Lua state is prepared to execute the 00249 * Lua function with the same semantics as used for SWIG generated wrappers 00250 * of C++ functions. 00251 * 00252 * If you pass NULL as destination state, the global state will be used. 00253 * 00254 * @param pL 00255 * Reference to the Lua state 00256 */ 00257 void Install(LuaState* pL=NULL) const; 00258 00259 /** 00260 * Install this function to a Lua state. 00261 * 00262 * Alternative signature for applications that do not use the 00263 * the LuaState wrapper class. See also Install(LuaState*). 00264 * 00265 * @param pLL 00266 * Reference to the Lua state 00267 */ 00268 void Install(lua_State* pLL) const; 00269 00270 00271 /* 00272 * Register LuaExtension with the run-time-interface. 00273 * 00274 * This static convenience method registers all LuaFunctionDefinitions found 00275 * in an extension file with the FunctionRegistry. Thus, after registration 00276 * you can use the Lua function via the run-time-interface as if they 00277 * where C++ functions. 00278 * 00279 * Note: if you also want to use the provided functions within a Lua interpreter, 00280 * you must also install the extension to a lua state. This can be done on 00281 * a per-file basis by LuaState::Install(const std::string&) or for the any 00282 * functions registered by LuaState::Reset(). 00283 * 00284 * 00285 * @param rFilename 00286 * Source file (typically .flx) 00287 */ 00288 static void Register(const std::string& rFilename); 00289 00290 00291 protected: 00292 00293 /** 00294 * Std faudes type interface: assignment. 00295 * 00296 * @param rSrc 00297 * Source to copy from 00298 * @return Reference to this object. 00299 */ 00300 virtual void DoAssign(const LuaFunctionDefinition& rSrc); 00301 00302 /** 00303 * Std faudes type interface: test equality 00304 * 00305 * @param rOther 00306 * Other object to compare with. 00307 * @return 00308 * True on match. 00309 */ 00310 virtual bool DoEqual(const LuaFunctionDefinition& rOther) const; 00311 00312 /** 00313 * Read configuration data of this object from TokenReader. 00314 * Actual reading is done by DoReadCore. 00315 * 00316 * The section defaults to "LuaFunctionDefinition", context ignored. 00317 * 00318 * @param rTr 00319 * TokenReader to read from 00320 * @param rLabel 00321 * Section to read 00322 * @param pContext 00323 * Read context to provide contextual information (ignored) 00324 * 00325 * @exception Exception 00326 * - Token mismatch (id 50, 51, 52) 00327 * - IO error (id 1) 00328 */ 00329 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0); 00330 00331 /** 00332 * Read configuration data of this object from TokenReader. 00333 * 00334 * This method reads members only, it does not read the section. 00335 * 00336 * @param rTr 00337 * TokenReader to read from 00338 * 00339 * @exception Exception 00340 * - Token mismatch (id 50, 51, 52) 00341 * - IO error (id 1) 00342 */ 00343 virtual void DoReadCore(TokenReader& rTr); 00344 00345 /** 00346 * Write configuration data of this object to TokenWriter. 00347 * 00348 * The section defaults to "LuaFunctionDefinition", context ignored. 00349 * 00350 * @param rTw 00351 * Reference to TokenWriter 00352 * @param rLabel 00353 * Label of section to write 00354 * @param pContext 00355 * Write context to provide contextual information 00356 * 00357 * @exception Exception 00358 * - IO errors (id 2) 00359 */ 00360 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const; 00361 00362 /** 00363 * Write configuration data of this object to TokenWriter. 00364 * 00365 * This method writes plain member data, the section lables are not 00366 * written. 00367 * 00368 * @param rTw 00369 * Reference to TokenWriter 00370 * 00371 * @exception Exception 00372 * - IO errors (id 2) 00373 */ 00374 virtual void DoWriteCore(TokenWriter& rTw) const; 00375 00376 00377 /** 00378 * Assign prototype object 00379 * 00380 * @param pFunc 00381 * Function instance 00382 * 00383 */ 00384 virtual void Prototype(Function* pFunc); 00385 00386 /** Typed prototype instance */ 00387 LuaFunction* pLuaFunction; 00388 00389 /** Lua code */ 00390 std::string mLuaCode; 00391 00392 /** Lua file */ 00393 std::string mLuaFile; 00394 00395 /** Default lua state*/ 00396 LuaState* pDefaultL; 00397 00398 }; 00399 00400 00401 /** 00402 * Wrapper class to maintain a Lua state. 00403 * 00404 * This class is still under construction. It aims for a sensible collection 00405 * of operations that we may want to execute on a Lua state from the libFAUDES 00406 * perspective. The current implementation provides static members that directly 00407 * operate on a lua_State as well as a more comfortable interface that 00408 * operates on thre wrapped faudes::LusState. 00409 * 00410 * @ingroup LuabindingsPlugin 00411 */ 00412 00413 class LuaState { 00414 public: 00415 /** 00416 * Constructor 00417 */ 00418 LuaState(void); 00419 00420 /** 00421 * Destructor 00422 */ 00423 ~LuaState(void); 00424 00425 /** 00426 * Access Lua state. 00427 */ 00428 lua_State* LL(void); 00429 00430 /** 00431 * Convenience global Lua state. 00432 */ 00433 static LuaState* G(void); 00434 00435 /** 00436 * Reinitialize Lua state. 00437 * 00438 * This method reconstructs the internal Lua state. 00439 * Any references become invalid. Any LuaFunctiondefinitions from 00440 * the FunctionRegistry will be (re-)installed to the new state. 00441 */ 00442 void Reset(void); 00443 00444 /** 00445 * Install LuaExtension to Lua state. 00446 * 00447 * This function instantiates a LuaFunctionDefinition objects from 00448 * the file and uses the Install member function to install each function 00449 * to the specified lua state. Thus, after the extension has been installed, 00450 * the respective Lua functions can be invoked within Lua as if they where 00451 * C++ function with SWIG generated wrappers. 00452 * 00453 * Note: if you want to use the extension via the run-time-interface, you 00454 * must also register them with the FunctionRegistry; see also the static method 00455 * LuaFunctionDefinition::Register(const std::string&). 00456 * 00457 * @param rFilename 00458 * Source file (typically .flx) 00459 */ 00460 void Install(const std::string& rFilename); 00461 00462 /** 00463 * Initialze. 00464 * 00465 * Loads std libraries and libFAUDES wrappers. 00466 * 00467 * Note: this static version is provided for applications 00468 * that maintain their lua state themselves. If yo use 00469 * the wrapper class LuaState, you dont need explicit 00470 * initialisation. 00471 * 00472 * @param pLL 00473 * Lua state 00474 */ 00475 static void Initialize(lua_State* pLL); 00476 00477 /** 00478 * Install LuaExtension to Lua state. 00479 * 00480 * Note: this static version is provided for applications 00481 * that maintain their lua state themselves. If yo use 00482 * the wrapper class LuaState, you should use the Install(const std::string&) method. 00483 * 00484 * @param pL 00485 * Target lua state 00486 * @param rFilename 00487 * Source file 00488 * @ingroup LuabindingsPlugin 00489 */ 00490 static void Install(lua_State* pLL, const std::string& rFilename); 00491 00492 /** 00493 * Push faudes typed object on the Lua stack. 00494 * 00495 * This method uses SWIG generated constructors to instantiate new Lua userdata 00496 * object of the same type as the specified data. It than invokes 00497 * the faudes Assign method to assign a copy. 00498 * 00499 * @param fdata 00500 * Data to push 00501 * @exception Exception 00502 * - Lua Error (id 49) 00503 * 00504 */ 00505 void Push(const Type* fdata); 00506 00507 /** 00508 * Push faudes typed object on the Lua stack. 00509 * 00510 * This static version is meant for applications that maintain 00511 * their Lus state themselves. See also Push(const Type&) 00512 * 00513 * @param pLL 00514 * Lua state 00515 * @param fdata 00516 * Data to push 00517 * @exception Exception 00518 * - Lua Error (id 49) 00519 * 00520 */ 00521 static void Push(lua_State* pLL, const Type* fdata); 00522 00523 /** 00524 * Pop faudes typed object from Lua stack. 00525 * 00526 * This method uses SWIG generated type casts to retrieve the 00527 * faudes object from the userdata on the top of the stack. 00528 * It then uses the faudes Copy() method to instantiate a copy, 00529 * to be owned by the caller. 00530 * 00531 * 00532 * @return 00533 * Destination for pop data 00534 * @exception Exception 00535 * - Lua Error (id 49) 00536 * 00537 */ 00538 Type* Pop(void); 00539 00540 /** 00541 * Pop faudes typed object from Lua stack. 00542 * 00543 * This static version is meant for applications that maintain 00544 * their Lua state themselves. See also Pop(const Type&) 00545 * 00546 * @param pLL 00547 * Lua state 00548 * @return 00549 * Destination for pop data 00550 * @exception Exception 00551 * - Lua Error (id 49) 00552 * 00553 */ 00554 static Type* Pop(lua_State* pLL); 00555 00556 /** 00557 * Get/set global data 00558 * 00559 * This method provides access to global variables. 00560 * To set a variable, provide a non-NULL fdata parameter. 00561 * If you obmitt the fdata paraneter, the default will indicate a 00562 * get operation. Here, the value is returned as a copy and 00563 * owned by the caller. 00564 * 00565 * An expection is thrown if the variable either does not exist, 00566 * or cannot be converted to a faudes::Type. 00567 * 00568 * @param gname 00569 * Name of global variable 00570 * @param fdata 00571 * Data to set 00572 * @exception Exception 00573 * - Lua Error (id 49) 00574 * 00575 */ 00576 Type* Global(const std::string& gname, const Type* fdata=0); 00577 00578 /** 00579 * Get/set global data 00580 * 00581 * This static version is meant for applications that maintain 00582 * their Lua state themselves. See also Globat(const std::string&, const Type*) 00583 * 00584 * @param pLL 00585 * Lua state 00586 * @param gname 00587 * Name of global variable 00588 * @param fdata 00589 * Data to set 00590 * @exception Exception 00591 * - Lua Error (id 49) 00592 * 00593 */ 00594 static Type* Global(lua_State* pLL, const std::string& gname, const Type* fdata=0); 00595 00596 /** 00597 * Evaluate Lua expression. 00598 * 00599 * This method runs the Lua-interpreter on the specified expression. 00600 * In the case of an error, an exception will be thrown. 00601 * 00602 * @exception Exception 00603 * - Lua Error (id 49) 00604 * 00605 */ 00606 void Evaluate(const std::string& expr); 00607 00608 /** 00609 * Evaluate Lua expression. 00610 * 00611 * This static version is meant for applications that maintain 00612 * their Lua state themselves. See also Evaluate(const std::string&) 00613 * 00614 * @param pLL 00615 * Lua state 00616 * @exception Exception 00617 * - Lua Error (id 49) 00618 * 00619 */ 00620 static void Evaluate(lua_State* pLL, const std::string& expr); 00621 00622 /** 00623 * Complete Lua identifier 00624 * 00625 * This method uses a variation of Mike Pall's advaced readline 00626 * support patch to fugure possible completions if a string 00627 * to match a valid identifyer. 00628 * 00629 * @param pLL 00630 * Lua state 00631 * @param word 00632 * String to complete 00633 * @return 00634 * List of completions, first entry is longest common prefix. 00635 */ 00636 std::list< std::string > Complete(const std::string& word); 00637 00638 /** 00639 * Complete Lua identifier 00640 * 00641 * This static version is meant for applications that maintain 00642 * their Lua state themselves. See also Evaluate(const std::string&) 00643 * 00644 * @param pLL 00645 * Lua state 00646 * @param word 00647 * String to complete 00648 * @return 00649 * List of completions, first entry is longest common prefix. 00650 */ 00651 static std::list< std::string > Complete(lua_State* pLL, const std::string& word); 00652 00653 00654 private: 00655 00656 // disable copy constructor 00657 LuaState(const LuaState&){}; 00658 // lua state 00659 lua_State* mpLL; 00660 // open/close lua state 00661 void Open(void); 00662 void Close(void); 00663 }; 00664 00665 00666 /** 00667 * A LuaFunction is a faudes-function that executes a luafaudes script. 00668 * 00669 * LuaFunction is derived from Function and implements the DoTypeCheck and DoExecute 00670 * interface to run the lua code as supplied by the corresponding function defintion. 00671 * Thus, it is considered an error to set the function definition to an object that 00672 * does not cast to a LuaFunctionDefinition. 00673 * 00674 * @ingroup LuabindingsPlugin 00675 */ 00676 00677 class LuaFunction : public Function { 00678 00679 public: 00680 /** 00681 * Constructor. 00682 * For the function to be operational, a valid reference to the corresponding 00683 * LuaFunctionDefinition is required. The only exception is the prototype function 00684 * object used in the LuaFunctionDefinition itself. 00685 */ 00686 LuaFunction(const LuaFunctionDefinition* fdef); 00687 00688 /** Destructor */ 00689 ~LuaFunction(void){}; 00690 00691 /** 00692 * Construct on heap. 00693 * Create a new instance of this function class and return pointer. 00694 * The new instance will use the same function definition as this instance. 00695 * 00696 * @return 00697 * Pointer to faudes::Function instance. 00698 * 00699 */ 00700 virtual LuaFunction* New() const; 00701 00702 00703 /** 00704 * Set function definition. 00705 * Normally, functions are provided with a function definition on construction. 00706 * The only exception are prototype objects used in function definitions themselfs 00707 * and in the function registry. 00708 * 00709 * @param fdef 00710 * Function definition to set. 00711 * 00712 */ 00713 void Definition(const FunctionDefinition* fdef); 00714 00715 00716 /** 00717 * Get function definition. 00718 * 00719 * @return 00720 * Function definition used by this function. 00721 * 00722 */ 00723 const LuaFunctionDefinition* Definition(void) const; 00724 00725 00726 /** 00727 * Syntax check lua code. 00728 * 00729 * This routine does all it needs to run the script, 00730 * except to invoke the specified function. The reasoning is, that 00731 * the script may hang and, thus, never return. A consequence 00732 * is, that you must set a variant and you must supply parameter 00733 * values befor checking. You may use AllocateValues() and FreeValues() 00734 * for this purpose. Errors are indicated by an exception. 00735 * 00736 * Note that the LuaFunctionDefinition provides a convenience wrapper 00737 * that runs the check on all variants and cares about value allocation. 00738 * 00739 * @exception Exception 00740 * - No such variant (id 47) 00741 * - Error in Lua script (id 49) 00742 */ 00743 void SyntaxCheck(void); 00744 00745 /** 00746 * Evaluate lua code. 00747 * 00748 * This routine avaluates the associated Lua code literally, i.e. 00749 * no arguments are passed, no specific function is invoked. 00750 * See also Execute(). 00751 * 00752 * @exception Exception 00753 * - Error in Lua script (id 49) 00754 */ 00755 void Evaluate(void); 00756 00757 00758 /** 00759 * Set lua state 00760 * 00761 * Sets the lua state which this function will use for execution. 00762 * If set to NULL (e.g. on consruction), the 00763 * function definition's default state will be used. If 00764 * this is not set either, the global state is used. 00765 * 00766 * @param l 00767 * Lua state 00768 */ 00769 void L(LuaState* l); 00770 00771 /** 00772 * Get default lua state 00773 * 00774 * @return 00775 * Lua state 00776 */ 00777 LuaState* L(void); 00778 00779 protected: 00780 00781 /* 00782 * Do set variant from function definition. 00783 * 00784 * For LuaFunctions, we accept the special variant -1 for 00785 * as "no variant", just run the script on execution. 00786 * 00787 * @param n 00788 * Variant index 00789 * 00790 * @exception Exception 00791 * - No function definition available (id 47) 00792 * - No such variant (id 48) 00793 */ 00794 virtual void DoVariant(int n); 00795 00796 00797 /** 00798 * Method to test the type of an assigned parameter with the 00799 * specified faudes::Signature (i.e. their TypeDefinition label). 00800 * 00801 * Note: this method is called by Function::Execute() before actual function 00802 * execution via DoExecute(). It may be used to perform a dynamic cast in 00803 * preparation of DoExecute(). The latter is only called, if all types match. 00804 * 00805 * @param n 00806 * Position of parameter to check 00807 * @return 00808 * True if type matches signature. 00809 * 00810 * @exception Exception 00811 * - Signature undefined (id 48) 00812 * - Parameter number out of range (id 48) 00813 */ 00814 virtual bool DoTypeCheck(int n); 00815 00816 /** 00817 * Executes code as supplied by FunctionDefinition 00818 * 00819 * @exception Exception 00820 * - Exception during lua setup (id 49) 00821 * - Any exception during execution of script 00822 */ 00823 virtual void DoExecute(); 00824 00825 /** 00826 * Execute stages 00827 * 00828 * @exception Exception 00829 * - Exception during lua setup (id 49) 00830 */ 00831 virtual void DoExecuteA(); 00832 00833 /** 00834 * Execute stages 00835 * 00836 * @exception Exception 00837 * - Exception during lua setup (id 49) 00838 */ 00839 virtual void DoExecuteB(); 00840 00841 /** 00842 * Execute stages 00843 * 00844 * @exception Exception 00845 * - Exception during lua setup (id 49) 00846 * - Any exception during execution of script 00847 */ 00848 virtual void DoExecuteC(); 00849 00850 /** 00851 * Execute stages 00852 * 00853 * @exception Exception 00854 * - Exception during lua setup (id 49) 00855 */ 00856 virtual void DoExecuteD(); 00857 00858 00859 /** 00860 * Execute stages 00861 * 00862 * @exception Exception 00863 * - Exception during lua setup (id 49) 00864 */ 00865 virtual void DoExecuteE(); 00866 00867 00868 /** Typed reference to definition */ 00869 const LuaFunctionDefinition* pLuaFuncDef; 00870 00871 /** State of Lua interpreter */ 00872 LuaState* pL; 00873 lua_State* pLL; 00874 int mFtable; 00875 int mEntryStack; 00876 void* mFType; 00877 std::vector<bool> mLReturn; 00878 std::vector<bool> mLParameter; 00879 int mLReturnCount; 00880 int mLParameterCount; 00881 }; 00882 00883 00884 00885 00886 00887 } // namespace 00888 #endif libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |