Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ODE/src/lib/script_engine/script.h @ 10304

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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