Use a settings object for the main settings
[oweals/minetest.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 #ifndef L_BASE_H_
21 #define L_BASE_H_
22
23 #include "common/c_types.h"
24 #include "common/c_internal.h"
25 #include "gamedef.h"
26
27 extern "C" {
28 #include <lua.h>
29 #include <lauxlib.h>
30 }
31
32 #ifndef SERVER
33 #include "client.h"
34 #endif
35
36 class ScriptApiBase;
37 class Server;
38 class Environment;
39 class GUIEngine;
40
41 class ModApiBase {
42
43 public:
44         static ScriptApiBase*   getScriptApiBase(lua_State *L);
45         static Server*          getServer(lua_State *L);
46         #ifndef SERVER
47         static Client*          getClient(lua_State *L);
48         #endif // !SERVER
49
50         static IGameDef*        getGameDef(lua_State *L);
51
52         static Environment*     getEnv(lua_State *L);
53         static GUIEngine*       getGuiEngine(lua_State *L);
54         // When we are not loading the mod, this function returns "."
55         static std::string      getCurrentModPath(lua_State *L);
56
57         // Get an arbitrary subclass of ScriptApiBase
58         // by using dynamic_cast<> on getScriptApiBase()
59         template<typename T>
60         static T* getScriptApi(lua_State *L) {
61                 ScriptApiBase *scriptIface = getScriptApiBase(L);
62                 T *scriptIfaceDowncast = dynamic_cast<T*>(scriptIface);
63                 if (!scriptIfaceDowncast) {
64                         throw LuaError("Requested unavailable ScriptApi - core engine bug!");
65                 }
66                 return scriptIfaceDowncast;
67         }
68
69         static bool registerFunction(lua_State *L,
70                         const char* name,
71                         lua_CFunction func,
72                         int top);
73 };
74
75 #endif /* L_BASE_H_ */