| 1 | #ifndef __SCRIPTABLE_H__ |
|---|
| 2 | #define __SCRIPTABLE_H__ |
|---|
| 3 | |
|---|
| 4 | #include <string> |
|---|
| 5 | #include <map> |
|---|
| 6 | #include <list> |
|---|
| 7 | |
|---|
| 8 | #include "VirtualMachine.h" |
|---|
| 9 | |
|---|
| 10 | namespace OrxScript |
|---|
| 11 | { |
|---|
| 12 | class LuaScript; |
|---|
| 13 | |
|---|
| 14 | //internal representation of a LuaScript |
|---|
| 15 | struct Script |
|---|
| 16 | { |
|---|
| 17 | int lastMethodIndex; |
|---|
| 18 | int methodBase; |
|---|
| 19 | int thisReference; |
|---|
| 20 | LuaScript* script; |
|---|
| 21 | int scriptReference; // reference to the script in its own lua_State |
|---|
| 22 | std::map<int, std::string> functionMap; |
|---|
| 23 | }; |
|---|
| 24 | |
|---|
| 25 | class Scriptable |
|---|
| 26 | { |
|---|
| 27 | friend class LuaScript; |
|---|
| 28 | |
|---|
| 29 | public: |
|---|
| 30 | Scriptable (void); |
|---|
| 31 | virtual ~Scriptable (void); |
|---|
| 32 | |
|---|
| 33 | // Method indexing check |
|---|
| 34 | int methods (LuaVirtualMachine& virtualMachine); |
|---|
| 35 | //int methods(){;return 1;} //BAD BAD HACK HACK HACK !!!!!!!!!!!!!! |
|---|
| 36 | |
|---|
| 37 | char whatIsThis(); |
|---|
| 38 | |
|---|
| 39 | // When the script calls a class method, this is called |
|---|
| 40 | virtual int scriptCalling (LuaVirtualMachine& vm, std::string functionName) = 0; |
|---|
| 41 | |
|---|
| 42 | // When the script function has returns |
|---|
| 43 | virtual void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc) = 0; |
|---|
| 44 | |
|---|
| 45 | std::string getFunctionAtIndex(int index, LuaVirtualMachine& virtualMachine); |
|---|
| 46 | |
|---|
| 47 | protected: |
|---|
| 48 | void registerFunction(std::string functionName);//Adds a function to the internal function list |
|---|
| 49 | private: |
|---|
| 50 | bool scriptableAdded(LuaScript* script, int scriptRef, int reference); |
|---|
| 51 | //void scriptableFunctionAdded(LuaScript* script, int reference); |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | Script* getScriptByPointer(LuaScript* script); |
|---|
| 55 | Script* getScriptByVirtualMachine(LuaVirtualMachine& virtualMachine); |
|---|
| 56 | std::map<int, std::string>* getFunctionMapByPointer(LuaScript* scriptPointer); |
|---|
| 57 | int getLastMethodIndexByPointer(LuaScript* script); |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | bool scriptIsInScriptList(LuaScript* script); |
|---|
| 61 | |
|---|
| 62 | void scriptDeleted(LuaScript* deleted); |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | std::list<std::string> functionList; |
|---|
| 67 | std::list<Script> scriptList; |
|---|
| 68 | }; |
|---|
| 69 | |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | #endif // __SCRIPTABLE_H__ |
|---|