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.
22 #include "common/c_types.h"
23 #include "common/c_internal.h"
24 #include "common/helper.h"
26 #include <unordered_map>
42 class ModApiBase : protected LuaHelper {
45 static ScriptApiBase* getScriptApiBase(lua_State *L);
46 static Server* getServer(lua_State *L);
48 static Client* getClient(lua_State *L);
51 static IGameDef* getGameDef(lua_State *L);
53 static Environment* getEnv(lua_State *L);
54 static GUIEngine* getGuiEngine(lua_State *L);
55 // When we are not loading the mod, this function returns "."
56 static std::string getCurrentModPath(lua_State *L);
58 // Get an arbitrary subclass of ScriptApiBase
59 // by using dynamic_cast<> on getScriptApiBase()
61 static T* getScriptApi(lua_State *L) {
62 ScriptApiBase *scriptIface = getScriptApiBase(L);
63 T *scriptIfaceDowncast = dynamic_cast<T*>(scriptIface);
64 if (!scriptIfaceDowncast) {
65 throw LuaError("Requested unavailable ScriptApi - core engine bug!");
67 return scriptIfaceDowncast;
70 static bool registerFunction(lua_State *L,
75 static int l_deprecated_function(lua_State *L);
76 static void markAliasDeprecated(luaL_Reg *reg);
78 // <old_name> = { <new_name>, <new_function> }
79 static std::unordered_map<std::string, luaL_Reg> m_deprecated_wrappers;
80 static bool m_error_deprecated_calls;