Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
l_base.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "common/c_types.h"
8#include "common/c_internal.h"
9#include "common/helper.h"
10#include "gamedef.h"
11#include <unordered_map>
12
13extern "C" {
14#include <lua.h>
15#include <lauxlib.h>
16}
17
18#if CHECK_CLIENT_BUILD()
19class Client;
20class GUIEngine;
21#endif
22class EmergeThread;
23class ScriptApiBase;
24class Server;
25class Environment;
27
28class ModApiBase : protected LuaHelper {
29public:
30 static ScriptApiBase* getScriptApiBase(lua_State *L);
31 static Server* getServer(lua_State *L);
33 #if CHECK_CLIENT_BUILD()
34 static Client* getClient(lua_State *L);
35 static GUIEngine* getGuiEngine(lua_State *L);
36 #endif // !SERVER
37 static EmergeThread* getEmergeThread(lua_State *L);
38
39 static IGameDef* getGameDef(lua_State *L);
40
41 static Environment* getEnv(lua_State *L);
42
43 // When we are not loading the mod, this function returns "."
44 static std::string getCurrentModPath(lua_State *L);
45
46 // Get an arbitrary subclass of ScriptApiBase
47 // by using dynamic_cast<> on getScriptApiBase()
48 template<typename T>
49 static T* getScriptApi(lua_State *L) {
50 ScriptApiBase *scriptIface = getScriptApiBase(L);
51 T *scriptIfaceDowncast = dynamic_cast<T*>(scriptIface);
52 if (!scriptIfaceDowncast) {
53 throw LuaError("Requested unavailable ScriptApi - core engine bug!");
54 }
55 return scriptIfaceDowncast;
56 }
57
58 static bool registerFunction(lua_State *L,
59 const char* name,
60 lua_CFunction func,
61 int top);
62
63 static void registerClass(lua_State *L, const char *name,
64 const luaL_Reg *methods,
65 const luaL_Reg *metamethods);
66
67 template<typename T>
68 static inline T *checkObject(lua_State *L, int narg)
69 {
70 return *reinterpret_cast<T**>(luaL_checkudata(L, narg, T::className));
71 }
72
86 static int l_deprecated_function(lua_State *L, const char *good, const char *bad, lua_CFunction func);
87};
Definition client.h:105
Definition emerge_internal.h:25
Definition environment.h:34
implementation of main menu based uppon formspecs
Definition guiEngine.h:113
Definition gamedef.h:36
Definition c_types.h:40
Definition helper.h:14
Definition l_base.h:28
static bool registerFunction(lua_State *L, const char *name, lua_CFunction func, int top)
Definition l_base.cpp:82
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:116
static void registerClass(lua_State *L, const char *name, const luaL_Reg *methods, const luaL_Reg *metamethods)
Definition l_base.cpp:93
static ServerInventoryManager * getServerInventoryMgr(lua_State *L)
Definition l_base.cpp:34
static Server * getServer(lua_State *L)
Definition l_base.cpp:29
static IGameDef * getGameDef(lua_State *L)
Definition l_base.cpp:46
static std::string getCurrentModPath(lua_State *L)
Definition l_base.cpp:68
static ScriptApiBase * getScriptApiBase(lua_State *L)
Definition l_base.cpp:15
static Environment * getEnv(lua_State *L)
Definition l_base.cpp:51
static T * getScriptApi(lua_State *L)
Definition l_base.h:49
static EmergeThread * getEmergeThread(lua_State *L)
Definition l_base.cpp:63
static T * checkObject(lua_State *L, int narg)
Definition l_base.h:68
Definition s_base.h:64
Definition serverinventorymgr.h:17
Definition server.h:166