Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ggz2/src/libraries/core/LuaState.h @ 8474

Last change on this file since 8474 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

  • Property svn:eol-style set to native
File size: 3.6 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    /**
48    @brief
49        Representation of an interface to lua
50    */
51    class _CoreExport LuaState
52    {
53// tolua_end
54    public:
55        LuaState();
56        ~LuaState();
57
58        void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
59        void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
60
61        void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
62        void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
63
64        void luaPrint(const std::string& str); // tolua_export
65        void luaLog(unsigned int level, const std::string& message); // tolua_export
66        bool fileExists(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
67
68        const std::stringstream& getOutput() const { return output_; }
69        void clearOutput() { output_.clear(); } // tolua_export
70
71        void setIncludeParser(std::string (*function)(const std::string&)) { includeParseFunction_ = function; }
72        lua_State* getInternalLuaState() { return luaState_; }
73
74        static bool addToluaInterface(int (*function)(lua_State*), const std::string& name);
75        static bool removeToluaInterface(const std::string& name);
76        static void openToluaInterfaces(lua_State* state);
77        static void closeToluaInterfaces(lua_State* state);
78
79    private:
80        shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths);
81
82#if LUA_VERSION_NUM != 501
83        struct LoadS
84        {
85            const char* s;
86            size_t size;
87        };
88
89        static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
90#endif
91
92        std::stringstream output_;
93        lua_State* luaState_;
94        bool bIsRunning_;
95        shared_ptr<ResourceInfo> sourceFileInfo_;
96        std::string (*includeParseFunction_)(const std::string&);
97
98        typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap;
99        static ToluaInterfaceMap toluaInterfaces_s;
100        static std::vector<LuaState*> instances_s;
101    }; // tolua_export
102} // tolua_export
103
104#endif /* _LuaState_H__ */
Note: See TracBrowser for help on using the repository browser.