Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/script_engine/script.h @ 9235

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

merged the presentation back

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    void registerClass(const std::string& className);                           //!< Register a class but dont add any instances
35
36    /// QUERRYING
37    /** @returns fileName */
38    std::string getFileName() { return currentFile; }
39    lua_State* getLuaState() const { return luaState; }
40
41
42
43    /// EXECUTING
44    // first select function
45    bool selectFunction(const std::string& functionName, int retCount);
46
47    // push parameters for luafunction
48    bool  pushParam(int param, std::string& toFunction);
49    bool  pushParam(float param, std::string& toFunction);
50    bool  pushParam(double param, std::string& toFunction);
51
52    // Execute the Function
53    bool executeFunction();
54
55     // get returned values in the order the lua function returns it
56    int   getReturnedInt();
57    bool  getReturnedBool();
58    float getReturnedFloat();
59    void  getReturnedString(std::string& string);
60
61    bool executeFile();
62
63  private:
64    void addThisScript();
65    int  reportError(int error);                      //!< Get errormessage from the lua stack and print it.
66    bool registerStandartClasses();                   //!< Register all the classes that the script might need
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.