Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added script_engine

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