Changeset 5654 for code/branches/resource2/src/core/LuaState.h
- Timestamp:
- Aug 17, 2009, 4:37:10 PM (16 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource2/src/core/LuaState.h
r5645 r5654 22 22 * Author: 23 23 * Benjamin Knecht 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 27 28 */ 28 29 29 /** 30 @file 31 @brief Representation of an interface to lua 32 @author Benjamin Knecht <beni_at_orxonox.net> 33 */ 34 35 #ifndef _LuaBind_H__ 36 #define _LuaBind_H__ 30 #ifndef _LuaState_H__ 31 #define _LuaState_H__ 37 32 38 33 #include "CorePrereqs.h" 39 34 40 #include <cassert> 35 #include <map> 36 #include <sstream> 41 37 #include <string> 42 38 #include <vector> 43 extern "C" { 44 #include <lua.h> 45 } 39 #include <boost/shared_ptr.hpp> 46 40 47 #include "util/S ingleton.h"41 #include "util/ScopeGuard.h" 48 42 49 43 // tolua_begin 50 44 namespace orxonox 51 45 { 52 class _CoreExport LuaBind : public Singleton<LuaBind> 53 { 46 /** 47 @brief 48 Representation of an interface to lua 49 */ 50 class _CoreExport LuaState 51 { 54 52 // tolua_end 55 friend class Singleton<LuaBind>; 53 public: 54 LuaState(); 55 ~LuaState(); 56 56 57 struct LoadS { 58 const char *s; 59 size_t size; 60 }; 57 void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export 58 void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 61 59 62 public: 63 LuaBind(); 64 ~LuaBind(); 60 void includeFile(const std::string& filename, const std::string& resourceGroup = "Genreal", bool bSearchOtherPaths = true); // tolua_export 61 void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 65 62 66 static LuaBind& getInstance() { return Singleton<LuaBind>::getInstance(); } // tolua_export 63 void luaPrint(const std::string& str); // tolua_export 64 void luaLog(unsigned int level, const std::string& message); // tolua_export 67 65 68 void loadFile(const std::string& filename, bool luaTags); 69 void loadString(const std::string& code); 70 //void init(lua_State *state_); 71 //void xmlToLua(); 72 void run(); 73 void luaPrint(const std::string& str); // tolua_export 66 const std::stringstream& getOutput() const { return output_; } 67 void clearOutput() { output_.clear(); } // tolua_export 68 69 void setIncludeParser(std::string (*function)(const std::string&)) { includeParseFunction_ = function; } 70 lua_State* getInternalLuaState() { return luaState_; } 71 72 static bool addToluaInterface(int (*function)(lua_State*), const std::string& name); 73 static bool removeToluaInterface(const std::string& name); 74 static void openToluaInterfaces(lua_State* state); 75 static void closeToluaInterfaces(lua_State* state); 76 77 private: 78 shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths); 74 79 75 80 #if LUA_VERSION_NUM != 501 76 static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size); 81 struct LoadS 82 { 83 const char* s; 84 size_t size; 85 }; 86 87 static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size); 77 88 #endif 78 89 79 inline lua_State* getLuaState() { return luaState_; }; 80 inline const std::string& getLuaOutput() { return output_; }; 81 //inline std::string* getFileString() { return &fileString_; }; 82 inline void clearLuaOutput() { output_ = ""; } 90 std::stringstream output_; 91 lua_State* luaState_; 92 bool bIsRunning_; 93 shared_ptr<ResourceInfo> sourceFileInfo_; 94 std::string (*includeParseFunction_)(const std::string&); 83 95 84 std::string replaceLuaTags(const std::string& text); // tolua_export 96 typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap; 97 static ToluaInterfaceMap toluaInterfaces_s; 98 static std::vector<LuaState*> instances_s; 99 }; // tolua_export 100 } // tolua_export 85 101 86 inline void setIncludePath(const std::string& includepath) 87 { this->includePath_ = includepath; } 88 89 void addToluaInterface(int (*function)(lua_State*), const std::string& name); 90 void openToluaInterfaces(lua_State* state); 91 void closeToluaInterfaces(lua_State* state); 92 93 private: 94 static LuaBind* singletonPtr_s; 95 96 std::string luaSource_; 97 std::string output_; 98 lua_State* luaState_; 99 bool isRunning_; 100 std::string includePath_; 101 std::vector<std::pair<std::string, int (*)(lua_State *L)> > toluaInterfaces_; 102 103 }; // tolua_export 104 } // tolua_export 105 #endif /* _LuaBind_H__ */ 102 #endif /* _LuaState_H__ */
Note: See TracChangeset
for help on using the changeset viewer.