Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/script_engine/script.h @ 9468

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

orxonox/trunk: merged the branche scripting back here.

merged with command:
svn merge -r9239:HEAD https://svn.orxonox.net/orxonox/branches/scripting .
no conflicts

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