Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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