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 | |
---|
9 | namespace OrxScript |
---|
10 | { |
---|
11 | |
---|
12 | struct Scrptbl |
---|
13 | { |
---|
14 | Scriptable* scriptable; |
---|
15 | int scriptableRef; |
---|
16 | }; |
---|
17 | |
---|
18 | class LuaScript |
---|
19 | { |
---|
20 | public: |
---|
21 | LuaScript (); |
---|
22 | virtual ~LuaScript (void); |
---|
23 | |
---|
24 | |
---|
25 | void init(LuaVirtualMachine& vm); |
---|
26 | |
---|
27 | /* ------------------ Script related Functions ------------------ */ |
---|
28 | |
---|
29 | // Compile script into Virtual Machine |
---|
30 | bool compileFile (const std::string& strFilename); |
---|
31 | bool compileBuffer (unsigned char *pbBuffer, size_t szLen); |
---|
32 | |
---|
33 | // Register function with Lua in the this table |
---|
34 | int registerFunction (const std::string& strFuncName); |
---|
35 | |
---|
36 | |
---|
37 | // Selects a Lua Script function to call |
---|
38 | bool selectScriptFunction (const std::string& strFuncName); |
---|
39 | void addParam (int iInt); |
---|
40 | void addParam (float fFloat); |
---|
41 | void addParam (const std::string& string); |
---|
42 | |
---|
43 | // Runs the loaded script |
---|
44 | bool run (int nReturns = 0); |
---|
45 | |
---|
46 | // Checks on Virtual Machine script |
---|
47 | bool scriptHasFunction (const std::string& strScriptName); |
---|
48 | |
---|
49 | // Method indexing check |
---|
50 | int methods (void) { return methodCount; } |
---|
51 | |
---|
52 | |
---|
53 | // When the script calls a class method, this is called |
---|
54 | virtual int scriptCalling (LuaVirtualMachine& vm, int iFunctionNumber) = 0; |
---|
55 | |
---|
56 | // When the script function has returns |
---|
57 | virtual void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc) = 0; |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | /* ------------------- Handle external Objects ------------------ */ |
---|
62 | |
---|
63 | void removeFromScript(int referenceToScriptable) {} |
---|
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); |
---|
66 | |
---|
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); |
---|
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; |
---|
88 | }; |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | #endif // __LUA_SCRIPT_BASE_H__ |
---|