Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/LuaState.h @ 7284

Last change on this file since 7284 was 7284, checked in by landauf, 14 years ago

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

  • Property svn:eol-style set to native
File size: 4.3 KB
RevLine 
[1959]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
[5654]24 *      Reto Grieder
[1959]25 *   Co-authors:
26 *      ...
27 *
28 */
29
[5654]30#ifndef _LuaState_H__
31#define _LuaState_H__
[1959]32
33#include "CorePrereqs.h"
34
[5654]35#include <map>
36#include <sstream>
[3196]37#include <string>
[3370]38#include <vector>
[5654]39#include <boost/shared_ptr.hpp>
[7266]40#include <loki/ScopeGuard.h>
[1959]41
[5655]42#include "ToluaInterface.h"
[3370]43
[6417]44namespace orxonox // tolua_export
45{ // tolua_export
[7284]46    class LuaFunctor; // tolua_export
[6417]47
[7284]48    //! callback class that executes lua code
49    class _CoreExport LuaFunctor
[6417]50    {
51        public:
52            LuaFunctor(const std::string& code, LuaState* luaState);
[7284]53            void operator()();
[6417]54
55        private:
56            std::string code_;
57            LuaState*   lua_;
58    };
59
60
[5654]61    /**
62    @brief
63        Representation of an interface to lua
64    */
[6417]65    class _CoreExport LuaState // tolua_export
66    { // tolua_export
[5654]67    public:
68        LuaState();
69        ~LuaState();
[2710]70
[6746]71        bool doFile(const std::string& filename); // tolua_export
72        bool doString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>());
[1959]73
[6746]74        bool includeFile(const std::string& filename); // tolua_export
75        bool includeString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>());
[1959]76
[5654]77        void luaPrint(const std::string& str); // tolua_export
78        void luaLog(unsigned int level, const std::string& message); // tolua_export
[6417]79        bool fileExists(const std::string& filename); // tolua_export
[6746]80        std::string getSourceCode(const std::string& filename); // tolua_export
[2662]81
[5654]82        const std::stringstream& getOutput() const { return output_; }
83        void clearOutput() { output_.clear(); } // tolua_export
[1959]84
[5654]85        void setIncludeParser(std::string (*function)(const std::string&)) { includeParseFunction_ = function; }
86        lua_State* getInternalLuaState() { return luaState_; }
[1959]87
[6417]88        void setDefaultResourceInfo(const shared_ptr<ResourceInfo>& sourceFileInfo) { this->sourceFileInfo_ = sourceFileInfo; }
89        const shared_ptr<ResourceInfo>& getDefaultResourceInfo() { return this->sourceFileInfo_; }
90
[7284]91        LuaFunctor* createLuaFunctor(const std::string& code) { return new LuaFunctor(code, this); } // tolua_export
[6746]92        //! Tells about whether IOConsole was activated. The Lua debugger only works with a normal console.
93        bool usingIOConsole() const; // tolua_export
[6417]94
[5654]95        static bool addToluaInterface(int (*function)(lua_State*), const std::string& name);
96        static bool removeToluaInterface(const std::string& name);
97        static void openToluaInterfaces(lua_State* state);
98        static void closeToluaInterfaces(lua_State* state);
[1959]99
[6763]100        static const std::string ERROR_HANDLER_NAME;
101
[5654]102    private:
[6417]103        shared_ptr<ResourceInfo> getFileInfo(const std::string& filename);
[1959]104
[5654]105#if LUA_VERSION_NUM != 501
106        struct LoadS
107        {
108            const char* s;
109            size_t size;
110        };
[2026]111
[5654]112        static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
113#endif
[3370]114
[5654]115        std::stringstream output_;
116        lua_State* luaState_;
117        bool bIsRunning_;
118        shared_ptr<ResourceInfo> sourceFileInfo_;
[6746]119        std::map<std::string, std::string> sourceCodeMap_;
[5654]120        std::string (*includeParseFunction_)(const std::string&);
[1959]121
[5654]122        typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap;
123        static ToluaInterfaceMap toluaInterfaces_s;
124        static std::vector<LuaState*> instances_s;
125    }; // tolua_export
126} // tolua_export
[1959]127
[5654]128#endif /* _LuaState_H__ */
Note: See TracBrowser for help on using the repository browser.