Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10581 was 10381, checked in by patrick, 18 years ago

merged script branche to turnk

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