Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10765 was 10622, checked in by snellen, 18 years ago

merged scriptimprovements back to trunk

File size: 3.0 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
[10622]70    bool addStandartObjects();                        //!< Add all the objects that the script might need
[8207]71    bool classIsRegistered(const std::string& type);  //!< Checks wheter the class "type" has already been registered with the script
72    bool objectIsAdded(const std::string& name);      //!< Checks wheter the object "name" has already been added to the script
[8075]73
[8206]74    lua_State*              luaState;                //!< The lua_State that the Script works on
75    std::string             currentFile;             //!< The file that is loaded in the script
76    std::string             currentFunction;         //!< The name of the current active function (the one that gets the pushed parameter)
77    int                     argumentCount;           //!< Number of arguments for the current function
78    int                     returnCount;             //!< Number of return values of the current function
[8362]79
[8207]80    std::list<WorldObject>  registeredObjects;       //!< The list of all the objects and their type that have been registered with this script
[8075]81
82
83
84};
85#endif /* _SCRIPT_H */
Note: See TracBrowser for help on using the repository browser.