Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.old/src/lib/script_engine/script.h @ 9777

Last change on this file since 9777 was 9061, checked in by patrick, 18 years ago

merged the single_player branche to trunk

File size: 2.7 KB
Line 
1/*!
2 * @file scrip.h
3 *  wrapper for a lua_State
4 */
5
6#ifndef _SCRIPT_H
7#define _SCRIPT_H
8
9
10#include "base_object.h"
11
12#include <list>
13
14struct lua_State;
15
16struct WorldObject
17{
18  std::string name;
19  std::string type;
20};
21
22class Script : public BaseObject
23{
24  public:
25    Script(const TiXmlElement* root = NULL);
26    ~Script();
27
28    /// LOADING
29    void loadParams(const TiXmlElement* root);
30
31    void loadFileNoRet(const std::string& filename) { loadFile(filename); };
32    bool loadFile(const std::string& filename);
33    void addObject( const std::string& className,const std::string& objectName);
34
35    /// QUERRYING
36    /** @returns fileName */
37    std::string getFileName() { return currentFile; }
38    lua_State* getLuaState() const { return luaState; }
39
40
41
42    /// EXECUTING
43    // first select function
44    bool selectFunction(const std::string& functionName, int retCount);
45
46    // push parameters for luafunction
47    bool  pushParam(int param, std::string& toFunction);
48    bool  pushParam(float param, std::string& toFunction);
49    bool  pushParam(double param, std::string& toFunction);
50
51    // Execute the Function
52    bool executeFunction();
53
54     // get returned values in the order the lua function returns it
55    int   getReturnedInt();
56    bool  getReturnedBool();
57    float getReturnedFloat();
58    void  getReturnedString(std::string& string);
59
60    bool executeFile();
61
62  private:
63    void addThisScript();
64    int  reportError(int error);                      //!< Get errormessage from the lua stack and print it.
65    bool registerStandartClasses();                   //!< Register all the classes that the script might need
66    bool registerClass(const std::string& className); //!< Register a class but dont add any instances
67    bool classIsRegistered(const std::string& type);  //!< Checks wheter the class "type" has already been registered with the script
68    bool objectIsAdded(const std::string& name);      //!< Checks wheter the object "name" has already been added to the script
69
70    lua_State*              luaState;                //!< The lua_State that the Script works on
71    std::string             currentFile;             //!< The file that is loaded in the script
72    std::string             currentFunction;         //!< The name of the current active function (the one that gets the pushed parameter)
73    int                     argumentCount;           //!< Number of arguments for the current function
74    int                     returnCount;             //!< Number of return values of the current function
75
76    std::list<WorldObject>  registeredObjects;       //!< The list of all the objects and their type that have been registered with this script
77
78
79
80};
81#endif /* _SCRIPT_H */
Note: See TracBrowser for help on using the repository browser.