[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] | 14 | struct lua_State; |
---|
[8075] | 15 | |
---|
[8207] | 16 | struct WorldObject |
---|
[8206] | 17 | { |
---|
| 18 | std::string name; |
---|
| 19 | std::string type; |
---|
| 20 | }; |
---|
| 21 | |
---|
[8193] | 22 | class 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); |
---|
[9235] | 34 | void registerClass(const std::string& className); //!< Register a class but dont add any instances |
---|
[8362] | 35 | |
---|
[8206] | 36 | /// QUERRYING |
---|
[8193] | 37 | /** @returns fileName */ |
---|
| 38 | std::string getFileName() { return currentFile; } |
---|
| 39 | lua_State* getLuaState() const { return luaState; } |
---|
| 40 | |
---|
| 41 | |
---|
[8362] | 42 | |
---|
[8193] | 43 | /// EXECUTING |
---|
| 44 | // first select function |
---|
[9061] | 45 | bool selectFunction(const std::string& functionName, int retCount); |
---|
[8193] | 46 | |
---|
[8075] | 47 | // push parameters for luafunction |
---|
[8093] | 48 | bool pushParam(int param, std::string& toFunction); |
---|
[8075] | 49 | bool pushParam(float param, std::string& toFunction); |
---|
| 50 | bool pushParam(double param, std::string& toFunction); |
---|
[8193] | 51 | |
---|
| 52 | // Execute the Function |
---|
| 53 | bool executeFunction(); |
---|
[8362] | 54 | |
---|
[8408] | 55 | // get returned values in the order the lua function returns it |
---|
[8093] | 56 | int getReturnedInt(); |
---|
[8075] | 57 | bool getReturnedBool(); |
---|
| 58 | float getReturnedFloat(); |
---|
[8155] | 59 | void getReturnedString(std::string& string); |
---|
[8075] | 60 | |
---|
[8193] | 61 | bool executeFile(); |
---|
[8075] | 62 | |
---|
| 63 | private: |
---|
[9003] | 64 | void addThisScript(); |
---|
[8206] | 65 | int reportError(int error); //!< Get errormessage from the lua stack and print it. |
---|
[8711] | 66 | bool registerStandartClasses(); //!< Register all the classes that the script might need |
---|
[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 */ |
---|