]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_base.h
Add HTTP API to main menu (#9998)
[dragonfireclient.git] / src / script / lua_api / l_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 #pragma once
21
22 #include "common/c_types.h"
23 #include "common/c_internal.h"
24 #include "common/helper.h"
25 #include "gamedef.h"
26 #include <unordered_map>
27
28 extern "C" {
29 #include <lua.h>
30 #include <lauxlib.h>
31 }
32
33 #ifndef SERVER
34 class Client;
35 class GUIEngine;
36 #endif
37
38 class ScriptApiBase;
39 class Server;
40 class Environment;
41 class ServerInventoryManager;
42
43 class ModApiBase : protected LuaHelper {
44
45 public:
46         static ScriptApiBase*   getScriptApiBase(lua_State *L);
47         static Server*          getServer(lua_State *L);
48         static ServerInventoryManager *getServerInventoryMgr(lua_State *L);
49         #ifndef SERVER
50         static Client*          getClient(lua_State *L);
51         static GUIEngine*       getGuiEngine(lua_State *L);
52         #endif // !SERVER
53
54         static IGameDef*        getGameDef(lua_State *L);
55
56         static Environment*     getEnv(lua_State *L);
57
58         // When we are not loading the mod, this function returns "."
59         static std::string      getCurrentModPath(lua_State *L);
60
61         // Get an arbitrary subclass of ScriptApiBase
62         // by using dynamic_cast<> on getScriptApiBase()
63         template<typename T>
64         static T* getScriptApi(lua_State *L) {
65                 ScriptApiBase *scriptIface = getScriptApiBase(L);
66                 T *scriptIfaceDowncast = dynamic_cast<T*>(scriptIface);
67                 if (!scriptIfaceDowncast) {
68                         throw LuaError("Requested unavailable ScriptApi - core engine bug!");
69                 }
70                 return scriptIfaceDowncast;
71         }
72
73         static bool registerFunction(lua_State *L,
74                         const char* name,
75                         lua_CFunction func,
76                         int top);
77
78         static int l_deprecated_function(lua_State *L);
79         static void markAliasDeprecated(luaL_Reg *reg);
80 private:
81         // <old_name> = { <new_name>, <new_function> }
82         static std::unordered_map<std::string, luaL_Reg> m_deprecated_wrappers;
83         static bool m_error_deprecated_calls;
84 };