| [7645] | 1 | #ifndef __LUA_SCRIPT_BASE_H__ |
|---|
| 2 | #define __LUA_SCRIPT_BASE_H__ |
|---|
| 3 | |
|---|
| 4 | #include <string> |
|---|
| 5 | |
|---|
| 6 | #include "VirtualMachine.h" |
|---|
| 7 | #include "scriptable.h" |
|---|
| 8 | |
|---|
| [7653] | 9 | namespace OrxScript |
|---|
| [7645] | 10 | { |
|---|
| 11 | |
|---|
| [7653] | 12 | struct Scrptbl |
|---|
| 13 | { |
|---|
| 14 | Scriptable* scriptable; |
|---|
| 15 | int scriptableRef; |
|---|
| 16 | }; |
|---|
| 17 | |
|---|
| 18 | class LuaScript |
|---|
| 19 | { |
|---|
| [7645] | 20 | public: |
|---|
| 21 | LuaScript (); |
|---|
| 22 | virtual ~LuaScript (void); |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | void init(LuaVirtualMachine& vm); |
|---|
| 26 | |
|---|
| 27 | /* ------------------ Script related Functions ------------------ */ |
|---|
| 28 | |
|---|
| [7653] | 29 | // Compile script into Virtual Machine |
|---|
| [7645] | 30 | bool compileFile (const std::string& strFilename); |
|---|
| 31 | bool compileBuffer (unsigned char *pbBuffer, size_t szLen); |
|---|
| 32 | |
|---|
| [7653] | 33 | // Register function with Lua in the this table |
|---|
| [7645] | 34 | int registerFunction (const std::string& strFuncName); |
|---|
| 35 | |
|---|
| 36 | |
|---|
| [7653] | 37 | // Selects a Lua Script function to call |
|---|
| [7645] | 38 | bool selectScriptFunction (const std::string& strFuncName); |
|---|
| 39 | void addParam (int iInt); |
|---|
| 40 | void addParam (float fFloat); |
|---|
| [7654] | 41 | void addParam (const std::string& string); |
|---|
| [7645] | 42 | |
|---|
| [7653] | 43 | // Runs the loaded script |
|---|
| [7645] | 44 | bool run (int nReturns = 0); |
|---|
| 45 | |
|---|
| [7653] | 46 | // Checks on Virtual Machine script |
|---|
| [7645] | 47 | bool scriptHasFunction (const std::string& strScriptName); |
|---|
| 48 | |
|---|
| [7653] | 49 | // Method indexing check |
|---|
| [7645] | 50 | int methods (void) { return methodCount; } |
|---|
| 51 | |
|---|
| 52 | |
|---|
| [7653] | 53 | // When the script calls a class method, this is called |
|---|
| [7645] | 54 | virtual int scriptCalling (LuaVirtualMachine& vm, int iFunctionNumber) = 0; |
|---|
| 55 | |
|---|
| [7653] | 56 | // When the script function has returns |
|---|
| [7645] | 57 | virtual void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc) = 0; |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | /* ------------------- Handle external Objects ------------------ */ |
|---|
| 62 | |
|---|
| [7654] | 63 | void removeFromScript(int referenceToScriptable) {} |
|---|
| [7653] | 64 | int addScriptableToScript(Scriptable* scriptbl,const std::string& name); // name= name the scriptable goes by in lua |
|---|
| 65 | int addFunctionToScriptable(const std::string& strFuncName, int toScriptable, int lastMethodIndex); |
|---|
| [7645] | 66 | |
|---|
| [7653] | 67 | //Handle the Scriptable List |
|---|
| 68 | Scriptable* getScriptableByReference(int scrptblRef); |
|---|
| 69 | int getReferenceByScriptable(Scriptable* scriptable); |
|---|
| 70 | bool addScriptableToList(Scriptable* scriptbl, int scriptableRef); |
|---|
| 71 | bool removeScriptableFromList(Scriptable* scriptable); |
|---|
| 72 | bool removeScriptableFromList(int scriptable); |
|---|
| [7645] | 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | /* ------------------ ... ------------------ */ |
|---|
| 77 | |
|---|
| 78 | LuaVirtualMachine& getVirtualMachine (void) { return virtualMachine; } |
|---|
| 79 | char whatIsThis(); |
|---|
| 80 | |
|---|
| 81 | protected: |
|---|
| 82 | int methodCount; |
|---|
| 83 | LuaVirtualMachine virtualMachine; |
|---|
| 84 | int thisReference; |
|---|
| 85 | int argumentCount; |
|---|
| 86 | std::string functionName; |
|---|
| 87 | std::list<Scrptbl> scriptableList; |
|---|
| [7653] | 88 | }; |
|---|
| [7645] | 89 | |
|---|
| [7653] | 90 | } |
|---|
| [7645] | 91 | |
|---|
| 92 | #endif // __LUA_SCRIPT_BASE_H__ |
|---|