Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/script_engine/src/lib/script_engine/Script.h @ 7653

Last change on this file since 7653 was 7653, checked in by bensch, 18 years ago

orxonox/script_engine: namespace OrxScript introduced

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