libFAUDES
Sections
Index
|
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 FanctionDefinition 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 theperspective 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 class LuaState { 00413 public: 00414 /* 00415 * Constructor 00416 */ 00417 LuaState(void); 00418 00419 /* 00420 * Destructor 00421 */ 00422 ~LuaState(void); 00423 00424 /* 00425 * Access Lua state. 00426 */ 00427 lua_State* LL(void); 00428 00429 /* 00430 * Convenience global Lua state. 00431 */ 00432 static LuaState* G(void); 00433 00434 /* 00435 * Reinitialize Lua state. 00436 * 00437 * This method reconstructs the internal Lua state. 00438 * Any references become invalid. Any LuaFunctiondefinitions from 00439 * the FunctionRegistry will be (re-)installed to the new state. 00440 */ 00441 void Reset(void); 00442 00443 /* 00444 * Install LuaExtension to Lua state. 00445 * 00446 * This function instantiates a LuaFunctionDefinition objects from 00447 * the file and uses the Install member function to install each function 00448 * to the specified lua state. Thus, after the extension has been installed, 00449 * the respective Lua functions can be invoked within Lua as if they where 00450 * C++ function with SWIG generated wrappers. 00451 * 00452 * Note: if you want to use the extension via the run-time-interface, you 00453 * must also register them with the FunctionRegistry; see also the static method 00454 * LuaFunctionDefinition::Register(const std::string&). 00455 * 00456 * @param rFilename 00457 * Source file (typically .flx) 00458 */ 00459 void Install(const std::string& rFilename); 00460 00461 /* 00462 * Initialze. 00463 * 00464 * Loads std libraries and libFAUDES wrappers. 00465 * 00466 * Note: this static version is provided for applications 00467 * that maintain their lua state themselves. If yo use 00468 * the wrapper class LuaState, you dont need explicit 00469 * initialisation. 00470 * 00471 * @param pLL 00472 * Lua state 00473 */ 00474 static void Initialize(lua_State* pLL); 00475 00476 /* 00477 * Install LuaExtension to Lua state. 00478 * 00479 * Note: this static version is provided for applications 00480 * that maintain their lua state themselves. If yo use 00481 * the wrapper class LuaState, you should use the Install(const std::string&) method. 00482 * 00483 * @param pL 00484 * Target lua state 00485 * @param rFilename 00486 * Source file 00487 * @ingroup LuabindingsPlugin 00488 */ 00489 static void Install(lua_State* pLL, const std::string& rFilename); 00490 00491 /* 00492 * Push faudes typed object on the Lua stack. 00493 * 00494 * This method uses SWIG generated constructors to instantiate new Lua userdata 00495 * object of the same type as the specified data. It than invokes 00496 * the faudes Assign method to assign a copy. 00497 * 00498 * @param fdata 00499 * Data to push 00500 * @exception Exception 00501 * - Lua Error (id 49) 00502 * 00503 */ 00504 void Push(const Type* fdata); 00505 00506 /* 00507 * Push faudes typed object on the Lua stack. 00508 * 00509 * This static version is meant for applications that maintain 00510 * their Lus state themselves. See also Push(const Type&) 00511 * 00512 * @param pLL 00513 * Lua state 00514 * @param fdata 00515 * Data to push 00516 * @exception Exception 00517 * - Lua Error (id 49) 00518 * 00519 */ 00520 static void Push(lua_State* pLL, const Type* fdata); 00521 00522 /* 00523 * Pop faudes typed object from Lua stack. 00524 * 00525 * This method uses SWIG generated type casts to retrieve the 00526 * faudes object from the userdata on the top of the stack. 00527 * It then uses the faudes Copy() method to instantiate a copy, 00528 * to be owned by the caller. 00529 * 00530 * 00531 * @return 00532 * Destination for pop data 00533 * @exception Exception 00534 * - Lua Error (id 49) 00535 * 00536 */ 00537 Type* Pop(void); 00538 00539 /* 00540 * Pop faudes typed object from Lua stack. 00541 * 00542 * This static version is meant for applications that maintain 00543 * their Lua state themselves. See also Pop(const Type&) 00544 * 00545 * @param pLL 00546 * Lua state 00547 * @return 00548 * Destination for pop data 00549 * @exception Exception 00550 * - Lua Error (id 49) 00551 * 00552 */ 00553 static Type* Pop(lua_State* pLL); 00554 00555 /* 00556 * Get/set global data 00557 * 00558 * This method provides access to global variables. 00559 * To set a variable, provide a non-NULL fdata parameter. 00560 * If you obmitt the fdata paraneter, the default will indicate a 00561 * get operation. Here, the value is returned as a copy and 00562 * owned by the caller. 00563 * 00564 * An expection is thrown if the variable either does not exist, 00565 * or cannot be converted to a faudes::Type. 00566 * 00567 * @param gname 00568 * Name of global variable 00569 * @param fdata 00570 * Data to set 00571 * @exception Exception 00572 * - Lua Error (id 49) 00573 * 00574 */ 00575 Type* Global(const std::string& gname, const Type* fdata=0); 00576 00577 /* 00578 * Get/set global data 00579 * 00580 * This static version is meant for applications that maintain 00581 * their Lua state themselves. See also Globat(const std::string&, const Type*) 00582 * 00583 * @param pLL 00584 * Lua state 00585 * @param gname 00586 * Name of global variable 00587 * @param fdata 00588 * Data to set 00589 * @exception Exception 00590 * - Lua Error (id 49) 00591 * 00592 */ 00593 static Type* Global(lua_State* pLL, const std::string& gname, const Type* fdata=0); 00594 00595 /* 00596 * Evaluate Lua expression. 00597 * 00598 * This method runs the Lua-interpreter on the specified expression. 00599 * In the case of an error, an exception will be thrown. 00600 * 00601 * @exception Exception 00602 * - Lua Error (id 49) 00603 * 00604 */ 00605 void Evaluate(const std::string& expr); 00606 00607 /* 00608 * Evaluate Lua expression. 00609 * 00610 * This static version is meant for applications that maintain 00611 * their Lua state themselves. See also Evaluate(const std::string&) 00612 * 00613 * @param pLL 00614 * Lua state 00615 * @exception Exception 00616 * - Lua Error (id 49) 00617 * 00618 */ 00619 static void Evaluate(lua_State* pLL, const std::string& expr); 00620 00621 /* 00622 * Complete Lua identifier 00623 * 00624 * This method uses a variation of Mike Pall's advaced readline 00625 * support patch to fugure possible completions if a string 00626 * to match a valid identifyer. 00627 * 00628 * @param pLL 00629 * Lua state 00630 * @param word 00631 * String to complete 00632 * @return 00633 * List of completions, first entry is longest common prefix. 00634 */ 00635 std::list< std::string > Complete(const std::string& word); 00636 00637 /* 00638 * Complete Lua identifier 00639 * 00640 * This static version is meant for applications that maintain 00641 * their Lua state themselves. See also Evaluate(const std::string&) 00642 * 00643 * @param pLL 00644 * Lua state 00645 * @param word 00646 * String to complete 00647 * @return 00648 * List of completions, first entry is longest common prefix. 00649 */ 00650 static std::list< std::string > Complete(lua_State* pLL, const std::string& word); 00651 00652 00653 private: 00654 00655 // disable copy constructor 00656 LuaState(const LuaState&){}; 00657 // lua state 00658 lua_State* mpLL; 00659 // open/close lua state 00660 void Open(void); 00661 void Close(void); 00662 }; 00663 00664 00665 /** 00666 * A LuaFunction is a faudes-function that executes a luafaudes script. 00667 * 00668 * LuaFunction is derived from Function and implements the DoTypeCheck and DoExecute 00669 * interface to run the lua code as supplied by the corresponding function defintion. 00670 * Thus, it is considered an error to set the function definition to an object that 00671 * does not cast to a LuaFunctionDefinition. 00672 * 00673 * @ingroup LuabindingsPlugin 00674 */ 00675 00676 class LuaFunction : public Function { 00677 00678 public: 00679 /** 00680 * Constructor. 00681 * For the function to be operational, a valid reference to the corresponding 00682 * LuaFunctionDefinition is required. The only exception is the prototype function 00683 * object used in the LuaFunctionDefinition itself. 00684 */ 00685 LuaFunction(const LuaFunctionDefinition* fdef); 00686 00687 /** Destructor */ 00688 ~LuaFunction(void){}; 00689 00690 /** 00691 * Construct on heap. 00692 * Create a new instance of this function class and return pointer. 00693 * The new instance will use the same function definition as this instance. 00694 * 00695 * @return 00696 * Pointer to faudes::Function instance. 00697 * 00698 */ 00699 virtual LuaFunction* New() const; 00700 00701 00702 /** 00703 * Set function definition. 00704 * Normally, functions are provided with a function definition on construction. 00705 * The only exception are prototype objects used in function definitions themselfs 00706 * and in the function registry. 00707 * 00708 * @param fdef 00709 * Function definition to set. 00710 * 00711 */ 00712 void Definition(const FunctionDefinition* fdef); 00713 00714 00715 /** 00716 * Get function definition. 00717 * 00718 * @return 00719 * Function definition used by this function. 00720 * 00721 */ 00722 const LuaFunctionDefinition* Definition(void) const; 00723 00724 00725 /** 00726 * Syntax check lua code. 00727 * 00728 * This routine does all it needs to run the script, 00729 * except to invoke the specified function. The reasoning is, that 00730 * the script may hang and, thus, never return. A consequence 00731 * is, that you must set a variant and you must supply parameter 00732 * values befor checking. You may use AllocateValues() and FreeValues() 00733 * for this purpose. Errors are indicated by an exception. 00734 * 00735 * Note that the LuaFunctionDefinition provides a convenience wrapper 00736 * that runs the check on all variants and cares about value allocation. 00737 * 00738 * @exception Exception 00739 * - No such variant (id 47) 00740 * - Error in Lua script (id 49) 00741 */ 00742 void SyntaxCheck(void); 00743 00744 /** 00745 * Evaluate lua code. 00746 * 00747 * This routine avaluates the associated Lua code literally, i.e. 00748 * no arguments are passed, no specific function is invoked. 00749 * See also Execute(). 00750 * 00751 * @exception Exception 00752 * - Error in Lua script (id 49) 00753 */ 00754 void Evaluate(void); 00755 00756 00757 /** 00758 * Set lua state 00759 * 00760 * Sets the lua state which this function will use for execution. 00761 * If set to NULL (e.g. on consruction), the 00762 * function definition's default state will be used. If 00763 * this is not set either, the global state is used. 00764 * 00765 * @param l 00766 * Lua state 00767 */ 00768 void L(LuaState* l); 00769 00770 /** 00771 * Get default lua state 00772 * 00773 * @return 00774 * Lua state 00775 */ 00776 LuaState* L(void); 00777 00778 protected: 00779 00780 /* 00781 * Do set variant from function definition. 00782 * 00783 * For LuaFunctions, we accept the special variant -1 for 00784 * as "no variant", just run the script on execution. 00785 * 00786 * @param n 00787 * Variant index 00788 * 00789 * @exception Exception 00790 * - No function definition available (id 47) 00791 * - No such variant (id 48) 00792 */ 00793 virtual void DoVariant(int n); 00794 00795 00796 /** 00797 * Method to test the type of an assigned parameter with the 00798 * specified faudes::Signature (i.e. their TypeDefinition label). 00799 * 00800 * Note: this method is called by Function::Execute() before actual function 00801 * execution via DoExecute(). It may be used to perform a dynamic cast in 00802 * preparation of DoExecute(). The latter is only called, if all types match. 00803 * 00804 * @param n 00805 * Position of parameter to check 00806 * @return 00807 * True if type matches signature. 00808 * 00809 * @exception Exception 00810 * - Signature undefined (id 48) 00811 * - Parameter number out of range (id 48) 00812 */ 00813 virtual bool DoTypeCheck(int n); 00814 00815 /** 00816 * Executes code as supplied by FunctionDefinition 00817 * 00818 * @exception Exception 00819 * - Exception during lua setup (id 49) 00820 * - Any exception during execution of script 00821 */ 00822 virtual void DoExecute(); 00823 00824 /** 00825 * Execute stages 00826 * 00827 * @exception Exception 00828 * - Exception during lua setup (id 49) 00829 */ 00830 virtual void DoExecuteA(); 00831 00832 /** 00833 * Execute stages 00834 * 00835 * @exception Exception 00836 * - Exception during lua setup (id 49) 00837 */ 00838 virtual void DoExecuteB(); 00839 00840 /** 00841 * Execute stages 00842 * 00843 * @exception Exception 00844 * - Exception during lua setup (id 49) 00845 * - Any exception during execution of script 00846 */ 00847 virtual void DoExecuteC(); 00848 00849 /** 00850 * Execute stages 00851 * 00852 * @exception Exception 00853 * - Exception during lua setup (id 49) 00854 */ 00855 virtual void DoExecuteD(); 00856 00857 00858 /** 00859 * Execute stages 00860 * 00861 * @exception Exception 00862 * - Exception during lua setup (id 49) 00863 */ 00864 virtual void DoExecuteE(); 00865 00866 00867 /** Typed reference to definition */ 00868 const LuaFunctionDefinition* pLuaFuncDef; 00869 00870 /** State of Lua interpreter */ 00871 LuaState* pL; 00872 lua_State* pLL; 00873 int mFtable; 00874 int mEntryStack; 00875 void* mFType; 00876 std::vector<bool> mLReturn; 00877 std::vector<bool> mLParameter; 00878 int mLReturnCount; 00879 int mLParameterCount; 00880 }; 00881 00882 00883 00884 00885 00886 } // namespace 00887 #endif |
libFAUDES 2.20s --- 2011.10.12 --- c++ source docu by doxygen