| [8075] | 1 | #ifndef _SCRIPT_H |
|---|
| 2 | #define _SCRIPT_H |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | #include "base_object.h" |
|---|
| 6 | |
|---|
| [8206] | 7 | |
|---|
| [8202] | 8 | struct lua_State; |
|---|
| [8075] | 9 | |
|---|
| [8207] | 10 | struct WorldObject |
|---|
| [8206] | 11 | { |
|---|
| 12 | std::string name; |
|---|
| 13 | std::string type; |
|---|
| 14 | }; |
|---|
| 15 | |
|---|
| [8193] | 16 | class Script : public BaseObject |
|---|
| [8075] | 17 | { |
|---|
| 18 | public: |
|---|
| [8193] | 19 | Script(const TiXmlElement* root = NULL); |
|---|
| [8075] | 20 | ~Script(); |
|---|
| [8193] | 21 | |
|---|
| 22 | /// LOADING |
|---|
| 23 | void loadParams(const TiXmlElement* root); |
|---|
| [8075] | 24 | |
|---|
| [8193] | 25 | void loadFileNoRet(const std::string& filename) { loadFile(filename); }; |
|---|
| 26 | bool loadFile(const std::string& filename); |
|---|
| [8206] | 27 | void addObject(const std::string& className, const std::string& objectName); |
|---|
| 28 | |
|---|
| 29 | /// QUERRYING |
|---|
| [8193] | 30 | /** @returns fileName */ |
|---|
| 31 | std::string getFileName() { return currentFile; } |
|---|
| 32 | lua_State* getLuaState() const { return luaState; } |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | /// EXECUTING |
|---|
| 37 | // first select function |
|---|
| [8075] | 38 | bool selectFunction(std::string& functionName, int retCount); |
|---|
| [8193] | 39 | |
|---|
| [8075] | 40 | // push parameters for luafunction |
|---|
| [8093] | 41 | bool pushParam(int param, std::string& toFunction); |
|---|
| [8075] | 42 | bool pushParam(float param, std::string& toFunction); |
|---|
| 43 | bool pushParam(double param, std::string& toFunction); |
|---|
| [8193] | 44 | |
|---|
| 45 | // Execute the Function |
|---|
| 46 | bool executeFunction(); |
|---|
| 47 | |
|---|
| 48 | // get returned values the last return value in lua is the first in c. TODO: change order of return |
|---|
| [8093] | 49 | int getReturnedInt(); |
|---|
| [8075] | 50 | bool getReturnedBool(); |
|---|
| 51 | float getReturnedFloat(); |
|---|
| [8155] | 52 | void getReturnedString(std::string& string); |
|---|
| [8075] | 53 | |
|---|
| [8193] | 54 | bool executeFile(); |
|---|
| [8075] | 55 | |
|---|
| 56 | private: |
|---|
| 57 | |
|---|
| [8206] | 58 | int reportError(int error); //!< Get errormessage from the lua stack and print it. |
|---|
| [8207] | 59 | bool classIsRegistered(const std::string& type); //!< Checks wheter the class "type" has already been registered with the script |
|---|
| 60 | bool objectIsAdded(const std::string& name); //!< Checks wheter the object "name" has already been added to the script |
|---|
| [8075] | 61 | |
|---|
| [8206] | 62 | lua_State* luaState; //!< The lua_State that the Script works on |
|---|
| 63 | std::string currentFile; //!< The file that is loaded in the script |
|---|
| 64 | std::string currentFunction; //!< The name of the current active function (the one that gets the pushed parameter) |
|---|
| 65 | int argumentCount; //!< Number of arguments for the current function |
|---|
| 66 | int returnCount; //!< Number of return values of the current function |
|---|
| 67 | |
|---|
| [8207] | 68 | std::list<WorldObject> registeredObjects; //!< The list of all the objects and their type that have been registered with this script |
|---|
| [8075] | 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | }; |
|---|
| 73 | #endif /* _SCRIPT_H */ |
|---|