]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/cpp_api/s_base.h
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.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 "jmutex.h"
32 #include "jmutexautolock.h"
33 #include "common/c_types.h"
34
35 #define SCRIPTAPI_LOCK_DEBUG
36
37 class Server;
38 class Environment;
39 class GUIEngine;
40 class ServerActiveObject;
41
42 class ScriptApiBase {
43 public:
44
45         ScriptApiBase();
46         virtual ~ScriptApiBase();
47
48         bool loadMod(const std::string &scriptpath, const std::string &modname);
49         bool loadScript(const std::string &scriptpath);
50
51         /* object */
52         void addObjectReference(ServerActiveObject *cobj);
53         void removeObjectReference(ServerActiveObject *cobj);
54
55 protected:
56         friend class LuaABM;
57         friend class InvRef;
58         friend class ObjectRef;
59         friend class NodeMetaRef;
60         friend class ModApiBase;
61         friend class ModApiEnvMod;
62         friend class LuaVoxelManip;
63
64         lua_State* getStack()
65                 { return m_luastack; }
66
67         void realityCheck();
68         void scriptError(const char *fmt, ...);
69         void stackDump(std::ostream &o);
70
71         Server* getServer() { return m_server; }
72         void setServer(Server* server) { m_server = server; }
73
74         Environment* getEnv() { return m_environment; }
75         void setEnv(Environment* env) { m_environment = env; }
76
77         GUIEngine* getGuiEngine() { return m_guiengine; }
78         void setGuiEngine(GUIEngine* guiengine) { m_guiengine = guiengine; }
79
80         void objectrefGetOrCreate(ServerActiveObject *cobj);
81         void objectrefGet(u16 id);
82
83         JMutex          m_luastackmutex;
84 #ifdef SCRIPTAPI_LOCK_DEBUG
85         bool            m_locked;
86 #endif
87 private:
88         lua_State*      m_luastack;
89
90         Server*         m_server;
91         Environment*    m_environment;
92         GUIEngine*      m_guiengine;
93 };
94
95 #endif /* S_BASE_H_ */