Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
l_base.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 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
28extern "C" {
29#include <lua.h>
30#include <lauxlib.h>
31}
32
33#ifndef SERVER
34class Client;
35class GUIEngine;
36#endif
37class EmergeThread;
38class ScriptApiBase;
39class Server;
40class Environment;
42
43class ModApiBase : protected LuaHelper {
44public:
45 static ScriptApiBase* getScriptApiBase(lua_State *L);
46 static Server* getServer(lua_State *L);
48 #ifndef SERVER
49 static Client* getClient(lua_State *L);
50 static GUIEngine* getGuiEngine(lua_State *L);
51 #endif // !SERVER
52 static EmergeThread* getEmergeThread(lua_State *L);
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 void registerClass(lua_State *L, const char *name,
79 const luaL_Reg *methods,
80 const luaL_Reg *metamethods);
81
82 template<typename T>
83 static inline T *checkObject(lua_State *L, int narg)
84 {
85 return *reinterpret_cast<T**>(luaL_checkudata(L, narg, T::className));
86 }
87
101 static int l_deprecated_function(lua_State *L, const char *good, const char *bad, lua_CFunction func);
102};
Definition: client.h:119
Definition: emerge_internal.h:40
Definition: environment.h:49
implementation of main menu based uppon formspecs
Definition: guiEngine.h:128
Definition: gamedef.h:51
Definition: c_types.h:55
Definition: helper.h:29
Definition: l_base.h:43
static bool registerFunction(lua_State *L, const char *name, lua_CFunction func, int top)
Definition: l_base.cpp:97
static int l_deprecated_function(lua_State *L, const char *good, const char *bad, lua_CFunction func)
A wrapper for deprecated functions.
Definition: l_base.cpp:131
static void registerClass(lua_State *L, const char *name, const luaL_Reg *methods, const luaL_Reg *metamethods)
Definition: l_base.cpp:108
static ServerInventoryManager * getServerInventoryMgr(lua_State *L)
Definition: l_base.cpp:49
static Server * getServer(lua_State *L)
Definition: l_base.cpp:44
static IGameDef * getGameDef(lua_State *L)
Definition: l_base.cpp:61
static std::string getCurrentModPath(lua_State *L)
Definition: l_base.cpp:83
static ScriptApiBase * getScriptApiBase(lua_State *L)
Definition: l_base.cpp:30
static Client * getClient(lua_State *L)
Definition: l_base.cpp:55
static Environment * getEnv(lua_State *L)
Definition: l_base.cpp:66
static GUIEngine * getGuiEngine(lua_State *L)
Definition: l_base.cpp:72
static T * getScriptApi(lua_State *L)
Definition: l_base.h:64
static EmergeThread * getEmergeThread(lua_State *L)
Definition: l_base.cpp:78
static T * checkObject(lua_State *L, int narg)
Definition: l_base.h:83
Definition: s_base.h:79
Definition: serverinventorymgr.h:32
Definition: server.h:146