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