Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
l_internal.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/******************************************************************************/
6/******************************************************************************/
7/* WARNING!!!! do NOT add this header in any include file or any code file */
8/* not being a modapi file!!!!!!!! */
9/******************************************************************************/
10/******************************************************************************/
11
12#pragma once
13
14#include "common/c_internal.h"
15
16#define luamethod(class, name) {#name, class::l_##name}
17
18#define luamethod_dep(class, good, bad) \
19 {#bad, [](lua_State *L) -> int { \
20 return l_deprecated_function(L, #good, #bad, &class::l_##good); \
21 }}
22
23#define luamethod_aliased(class, good, bad) \
24 luamethod(class, good), \
25 luamethod_dep(class, good, bad)
26
27#define API_FCT(name) registerFunction(L, #name, l_##name, top)
28
29// For future use
30#define MAP_LOCK_REQUIRED ((void)0)
31#define NO_MAP_LOCK_REQUIRED ((void)0)
32
33/* In debug mode ensure no code tries to retrieve the server env when it isn't
34 * actually available (in CSM) */
35#if CHECK_CLIENT_BUILD() && !defined(NDEBUG)
36#define DEBUG_ASSERT_NO_CLIENTAPI \
37 FATAL_ERROR_IF(getClient(L) != nullptr, "Tried " \
38 "to retrieve ServerEnvironment on client")
39#else
40#define DEBUG_ASSERT_NO_CLIENTAPI ((void)0)
41#endif
42
43// Retrieve ServerEnvironment pointer as `env` (no map lock)
44#define GET_ENV_PTR_NO_MAP_LOCK \
45 DEBUG_ASSERT_NO_CLIENTAPI; \
46 ServerEnvironment *env = (ServerEnvironment *)getEnv(L); \
47 if (env == NULL) \
48 return 0
49
50// Retrieve ServerEnvironment pointer as `env`
51#define GET_ENV_PTR \
52 MAP_LOCK_REQUIRED; \
53 GET_ENV_PTR_NO_MAP_LOCK
54
55// Retrieve Environment pointer as `env` (no map lock)
56#define GET_PLAIN_ENV_PTR_NO_MAP_LOCK \
57 Environment *env = getEnv(L); \
58 if (env == NULL) \
59 return 0
60
61// Retrieve Environment pointer as `env`
62#define GET_PLAIN_ENV_PTR \
63 MAP_LOCK_REQUIRED; \
64 GET_PLAIN_ENV_PTR_NO_MAP_LOCK