]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/cpp_api/s_base.h
Fix Windows build, clean up included headers
[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 "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 #define SCRIPT_MOD_NAME_FIELD "current_mod_name"
39 // MUST be an invalid mod name so that mods can't
40 // use that name to bypass security!
41 #define BUILTIN_MOD_NAME "*builtin*"
42
43
44 class Server;
45 class Environment;
46 class GUIEngine;
47 class ServerActiveObject;
48
49 class ScriptApiBase {
50 public:
51         ScriptApiBase();
52         virtual ~ScriptApiBase();
53
54         bool loadMod(const std::string &script_path, const std::string &mod_name);
55         bool loadScript(const std::string &script_path);
56
57         /* object */
58         void addObjectReference(ServerActiveObject *cobj);
59         void removeObjectReference(ServerActiveObject *cobj);
60
61         Server* getServer() { return m_server; }
62
63 protected:
64         friend class LuaABM;
65         friend class InvRef;
66         friend class ObjectRef;
67         friend class NodeMetaRef;
68         friend class ModApiBase;
69         friend class ModApiEnvMod;
70         friend class LuaVoxelManip;
71
72         lua_State* getStack()
73                 { return m_luastack; }
74
75         void realityCheck();
76         void scriptError();
77         void stackDump(std::ostream &o);
78
79         void setServer(Server* server) { m_server = server; }
80
81         Environment* getEnv() { return m_environment; }
82         void setEnv(Environment* env) { m_environment = env; }
83
84         GUIEngine* getGuiEngine() { return m_guiengine; }
85         void setGuiEngine(GUIEngine* guiengine) { m_guiengine = guiengine; }
86
87         void objectrefGetOrCreate(lua_State *L, ServerActiveObject *cobj);
88         void objectrefGet(lua_State *L, u16 id);
89
90         JMutex          m_luastackmutex;
91         // Stack index of Lua error handler
92         int             m_errorhandler;
93         bool            m_secure;
94 #ifdef SCRIPTAPI_LOCK_DEBUG
95         bool            m_locked;
96 #endif
97
98 private:
99         lua_State*      m_luastack;
100
101         Server*         m_server;
102         Environment*    m_environment;
103         GUIEngine*      m_guiengine;
104 };
105
106 #endif /* S_BASE_H_ */