Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/libraries/core/LuaState.h @ 6160

Last change on this file since 6160 was 6150, checked in by scheusso, 15 years ago

merged menu branch to presentation2 branch with some additional fixes and features ;)

  • 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    /**
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, const 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, const 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        void setDefaultResourceInfo(const shared_ptr<ResourceInfo>& sourceFileInfo) { this->sourceFileInfo_ = sourceFileInfo; }
75        const shared_ptr<ResourceInfo>& getDefaultResourceInfo() { return this->sourceFileInfo_; }
76
77        static bool addToluaInterface(int (*function)(lua_State*), const std::string& name);
78        static bool removeToluaInterface(const std::string& name);
79        static void openToluaInterfaces(lua_State* state);
80        static void closeToluaInterfaces(lua_State* state);
81
82    private:
83        shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths);
84
85#if LUA_VERSION_NUM != 501
86        struct LoadS
87        {
88            const char* s;
89            size_t size;
90        };
91
92        static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
93#endif
94
95        std::stringstream output_;
96        lua_State* luaState_;
97        bool bIsRunning_;
98        shared_ptr<ResourceInfo> sourceFileInfo_;
99        std::string (*includeParseFunction_)(const std::string&);
100
101        typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap;
102        static ToluaInterfaceMap toluaInterfaces_s;
103        static std::vector<LuaState*> instances_s;
104    }; // tolua_export
105} // tolua_export
106
107#endif /* _LuaState_H__ */
Note: See TracBrowser for help on using the repository browser.