Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10089 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
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);
[9869]36    void registerClass(const std::string& className);                           //!< Register a class but dont add any instances
[8362]37
[8206]38    /// QUERRYING
[8193]39    /** @returns fileName */
40    std::string getFileName() { return currentFile; }
41    lua_State* getLuaState() const { return luaState; }
42
43
[8362]44
[8193]45    /// EXECUTING
46    // first select function
[9061]47    bool selectFunction(const std::string& functionName, int retCount);
[8193]48
[8075]49    // push parameters for luafunction
[8093]50    bool  pushParam(int param, std::string& toFunction);
[8075]51    bool  pushParam(float param, std::string& toFunction);
52    bool  pushParam(double param, std::string& toFunction);
[8193]53
54    // Execute the Function
55    bool executeFunction();
[8362]56
[8408]57     // get returned values in the order the lua function returns it
[8093]58    int   getReturnedInt();
[8075]59    bool  getReturnedBool();
60    float getReturnedFloat();
[8155]61    void  getReturnedString(std::string& string);
[8075]62
[8193]63    bool executeFile();
[8075]64
65  private:
[9003]66    void addThisScript();
[8206]67    int  reportError(int error);                      //!< Get errormessage from the lua stack and print it.
[8711]68    bool registerStandartClasses();                   //!< Register all the classes that the script might need
[8207]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
[8075]71
[8206]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
[8362]77
[8207]78    std::list<WorldObject>  registeredObjects;       //!< The list of all the objects and their type that have been registered with this script
[8075]79
80
81
82};
83#endif /* _SCRIPT_H */
Note: See TracBrowser for help on using the repository browser.