]> git.lizzy.rs Git - minetest.git/blob - src/script/cpp_api/s_base.h
75552cc34f9bac163ba91fc14110b879834cde39
[minetest.git] / src / script / cpp_api / s_base.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef S_BASE_H_
21 #define S_BASE_H_
22
23 #include <iostream>
24 #include <string>
25
26 extern "C" {
27 #include <lua.h>
28 }
29
30 #include "irrlichttypes.h"
31 #include "jthread/jmutex.h"
32 #include "jthread/jmutexautolock.h"
33 #include "common/c_types.h"
34 #include "common/c_internal.h"
35
36 #define SCRIPTAPI_LOCK_DEBUG
37
38 class Server;
39 class Environment;
40 class GUIEngine;
41 class ServerActiveObject;
42
43 class ScriptApiBase {
44 public:
45
46         ScriptApiBase();
47         virtual ~ScriptApiBase();
48
49         bool loadMod(const std::string &scriptpath, const std::string &modname);
50         bool loadScript(const std::string &scriptpath);
51
52         /* object */
53         void addObjectReference(ServerActiveObject *cobj);
54         void removeObjectReference(ServerActiveObject *cobj);
55
56 protected:
57         friend class LuaABM;
58         friend class InvRef;
59         friend class ObjectRef;
60         friend class NodeMetaRef;
61         friend class ModApiBase;
62         friend class ModApiEnvMod;
63         friend class LuaVoxelManip;
64
65         lua_State* getStack()
66                 { return m_luastack; }
67
68         void realityCheck();
69         void scriptError();
70         void stackDump(std::ostream &o);
71
72         Server* getServer() { return m_server; }
73         void setServer(Server* server) { m_server = server; }
74
75         Environment* getEnv() { return m_environment; }
76         void setEnv(Environment* env) { m_environment = env; }
77
78         GUIEngine* getGuiEngine() { return m_guiengine; }
79         void setGuiEngine(GUIEngine* guiengine) { m_guiengine = guiengine; }
80
81         void objectrefGetOrCreate(ServerActiveObject *cobj);
82         void objectrefGet(u16 id);
83
84         JMutex          m_luastackmutex;
85 #ifdef SCRIPTAPI_LOCK_DEBUG
86         bool            m_locked;
87 #endif
88 private:
89         lua_State*      m_luastack;
90
91         Server*         m_server;
92         Environment*    m_environment;
93         GUIEngine*      m_guiengine;
94 };
95
96 #endif /* S_BASE_H_ */