Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: sandbox_light/src/libraries/core/LuaState.h @ 5910

Last change on this file since 5910 was 5782, checked in by rgrieder, 15 years ago

Applied changes to the real sandbox this time.

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Benjamin Knecht
24 *      Reto Grieder
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30#ifndef _LuaState_H__
31#define _LuaState_H__
32
33#include "CorePrereqs.h"
34
35#include <map>
36#include <sstream>
37#include <string>
38#include <vector>
39#include <boost/shared_ptr.hpp>
40
41#include "util/ScopeGuard.h"
42#include "ToluaInterface.h"
43
44// tolua_begin
45namespace orxonox
46{
47    //! Stores basic information about a File
48    struct ResourceInfo
49    {
50        //! The file's fully qualified name
51        std::string filename;
52        //! Path name; separated by '/' and ending with '/'
53        std::string path;
54        //! Base filename
55        std::string basename;
56    };
57
58    /**
59    @brief
60        Representation of an interface to lua
61    */
62    class _CoreExport LuaState
63    {
64// tolua_end
65    public:
66        LuaState();
67        ~LuaState();
68
69        void doFile(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export
70        void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
71
72        void includeFile(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export
73        void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
74
75        void luaPrint(const std::string& str); // tolua_export
76        void luaLog(unsigned int level, const std::string& message); // tolua_export
77        bool fileExists(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export
78
79        const std::stringstream& getOutput() const { return output_; }
80        void clearOutput() { output_.clear(); } // tolua_export
81
82        void setIncludeParser(std::string (*function)(const std::string&)) { includeParseFunction_ = function; }
83        lua_State* getInternalLuaState() { return luaState_; }
84
85        static bool addToluaInterface(int (*function)(lua_State*), const std::string& name);
86        static bool removeToluaInterface(const std::string& name);
87        static void openToluaInterfaces(lua_State* state);
88        static void closeToluaInterfaces(lua_State* state);
89
90    private:
91        shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, bool bSearchOtherPaths);
92        shared_ptr<ResourceInfo> getFileInfo(const std::string& filename);
93        std::string loadFile(const std::string& filename);
94
95#if LUA_VERSION_NUM != 501
96        struct LoadS
97        {
98            const char* s;
99            size_t size;
100        };
101
102        static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
103#endif
104
105        std::stringstream output_;
106        lua_State* luaState_;
107        bool bIsRunning_;
108        shared_ptr<ResourceInfo> sourceFileInfo_;
109        std::string (*includeParseFunction_)(const std::string&);
110
111        typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap;
112        static ToluaInterfaceMap toluaInterfaces_s;
113        static std::vector<LuaState*> instances_s;
114    }; // tolua_export
115} // tolua_export
116
117#endif /* _LuaState_H__ */
Note: See TracBrowser for help on using the repository browser.