Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the single_player_map branche back
merged with command:
svn merge -r8896:HEAD https://svn.orxonox.net/orxonox/branches/single_player_map .
no conflicts

File size: 2.7 KB
RevLine 
[8711]1/*!
2 * @file scrip.h
3 *  wrapper for a lua_State
4 */
5
[8075]6#ifndef _SCRIPT_H
7#define _SCRIPT_H
8
9
10#include "base_object.h"
11
[8362]12#include <list>
[8206]13
[8202]14struct lua_State;
[8075]15
[8207]16struct WorldObject
[8206]17{
18  std::string name;
19  std::string type;
20};
21
[8193]22class Script : public BaseObject
[8075]23{
24  public:
[8193]25    Script(const TiXmlElement* root = NULL);
[8075]26    ~Script();
[8362]27
[8193]28    /// LOADING
29    void loadParams(const TiXmlElement* root);
[8075]30
[8193]31    void loadFileNoRet(const std::string& filename) { loadFile(filename); };
32    bool loadFile(const std::string& filename);
[9003]33    void addObject( const std::string& className,const std::string& objectName);
[8362]34
[8206]35    /// QUERRYING
[8193]36    /** @returns fileName */
37    std::string getFileName() { return currentFile; }
38    lua_State* getLuaState() const { return luaState; }
39
40
[8362]41
[8193]42    /// EXECUTING
43    // first select function
[8075]44    bool selectFunction(std::string& functionName, int retCount);
[8193]45
[8075]46    // push parameters for luafunction
[8093]47    bool  pushParam(int param, std::string& toFunction);
[8075]48    bool  pushParam(float param, std::string& toFunction);
49    bool  pushParam(double param, std::string& toFunction);
[8193]50
51    // Execute the Function
52    bool executeFunction();
[8362]53
[8408]54     // get returned values in the order the lua function returns it
[8093]55    int   getReturnedInt();
[8075]56    bool  getReturnedBool();
57    float getReturnedFloat();
[8155]58    void  getReturnedString(std::string& string);
[8075]59
[8193]60    bool executeFile();
[8075]61
62  private:
[9003]63    void addThisScript();
[8206]64    int  reportError(int error);                      //!< Get errormessage from the lua stack and print it.
[8711]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
[8207]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
[8075]69
[8206]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
[8362]75
[8207]76    std::list<WorldObject>  registeredObjects;       //!< The list of all the objects and their type that have been registered with this script
[8075]77
78
79
80};
81#endif /* _SCRIPT_H */
Note: See TracBrowser for help on using the repository browser.