Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 17, 2009, 4:37:10 PM (15 years ago)
Author:
rgrieder
Message:
  • Implemented file management via resource manager and loading of resource locations via XML. Changes made:
    • SoundManager loads via memory stream rather than via file
    • Loader uses LuaState::includeFile() to load an XML file and passes the lua tag remover function to its LuaState.
    • ConfigFileManager still loads with hard paths because the files are required before Ogre gets created
  • Renamed LuaBind to LuaState, deSingletonised it and added new features:
    • doFile(), doString(), includeFile(), includeString() where include will preparse the string with a function provided with LuaState::setIncludeParser
    • Moved lua tags replace function to Loader (since it's actually an XML related task)
    • Using data_path/lua/LuaInitScript.lua to provide the following functions
      • logMessage(level, message)
      • doFile, dofile, include (all working with relative paths but within the same resource group)
  • Modified Script class to work with LuaState and fixed its XML Loader
  • Adjusted all level and include files (both "include" and "dofile" lua commands)
File:
1 moved

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/src/core/LuaState.h

    r5645 r5654  
    2222 *   Author:
    2323 *      Benjamin Knecht
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    2728 */
    2829
    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__
    3732
    3833#include "CorePrereqs.h"
    3934
    40 #include <cassert>
     35#include <map>
     36#include <sstream>
    4137#include <string>
    4238#include <vector>
    43 extern "C" {
    44 #include <lua.h>
    45 }
     39#include <boost/shared_ptr.hpp>
    4640
    47 #include "util/Singleton.h"
     41#include "util/ScopeGuard.h"
    4842
    4943// tolua_begin
    5044namespace orxonox
    5145{
    52   class _CoreExport LuaBind : public Singleton<LuaBind>
    53   {
     46    /**
     47    @brief
     48        Representation of an interface to lua
     49    */
     50    class _CoreExport LuaState
     51    {
    5452// tolua_end
    55     friend class Singleton<LuaBind>;
     53    public:
     54        LuaState();
     55        ~LuaState();
    5656
    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>());
    6159
    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>());
    6562
    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
    6765
    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);
    7479
    7580#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);
    7788#endif
    7889
    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&);
    8395
    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
    85101
    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.