3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
30 #include "irrlichttypes.h"
32 #include "threading/mutex_auto_lock.h"
33 #include "common/c_types.h"
34 #include "common/c_internal.h"
36 #define SCRIPTAPI_LOCK_DEBUG
37 #define SCRIPTAPI_DEBUG
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*"
43 #define PCALL_RES(RES) do { \
44 int result_ = (RES); \
46 scriptError(result_, __FUNCTION__); \
50 #define runCallbacks(nargs, mode) \
51 runCallbacksRaw((nargs), (mode), __FUNCTION__)
53 #define setOriginFromTable(index) \
54 setOriginFromTableRaw(index, __FUNCTION__)
63 class ServerActiveObject;
68 virtual ~ScriptApiBase();
70 // These throw a ModError on failure
71 void loadMod(const std::string &script_path, const std::string &mod_name);
72 void loadScript(const std::string &script_path);
74 void runCallbacksRaw(int nargs,
75 RunCallbacksMode mode, const char *fxn);
78 void addObjectReference(ServerActiveObject *cobj);
79 void removeObjectReference(ServerActiveObject *cobj);
81 IGameDef *getGameDef() { return m_gamedef; }
87 std::string getOrigin() { return m_last_run_mod; }
88 void setOriginDirect(const char *origin);
89 void setOriginFromTableRaw(int index, const char *fxn);
95 friend class ObjectRef;
96 friend class NodeMetaRef;
97 friend class ModApiBase;
98 friend class ModApiEnvMod;
99 friend class LuaVoxelManip;
101 lua_State* getStack()
102 { return m_luastack; }
105 void scriptError(int result, const char *fxn);
106 void stackDump(std::ostream &o);
108 void setGameDef(IGameDef* gamedef) { m_gamedef = gamedef; }
110 Environment* getEnv() { return m_environment; }
111 void setEnv(Environment* env) { m_environment = env; }
113 GUIEngine* getGuiEngine() { return m_guiengine; }
114 void setGuiEngine(GUIEngine* guiengine) { m_guiengine = guiengine; }
116 void objectrefGetOrCreate(lua_State *L, ServerActiveObject *cobj);
118 std::recursive_mutex m_luastackmutex;
119 std::string m_last_run_mod;
121 #ifdef SCRIPTAPI_LOCK_DEBUG
122 int m_lock_recursion_count;
123 threadid_t m_owning_thread;
127 static int luaPanic(lua_State *L);
129 lua_State* m_luastack;
132 Environment* m_environment;
133 GUIEngine* m_guiengine;
136 #endif /* S_BASE_H_ */