mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
scriptapi: Sort out ServerEnvironment / Environment distinction properly
The API implementation is shared between CSM and SSM. Functions should retrieve a plain env when they do not need any server-specific functions.
This commit is contained in:
parent
f105bc8dc2
commit
054c5dfaa3
7 changed files with 72 additions and 65 deletions
|
@ -32,14 +32,39 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define luamethod_aliased(class, name, alias) {#name, class::l_##name}, {#alias, class::l_##name}
|
||||
#define API_FCT(name) registerFunction(L, #name, l_##name, top)
|
||||
|
||||
#define MAP_LOCK_REQUIRED
|
||||
#define NO_MAP_LOCK_REQUIRED
|
||||
// For future use
|
||||
#define MAP_LOCK_REQUIRED ((void)0)
|
||||
#define NO_MAP_LOCK_REQUIRED ((void)0)
|
||||
|
||||
/* In debug mode ensure no code tries to retrieve the server env when it isn't
|
||||
* actually available (in CSM) */
|
||||
#if !defined(SERVER) && !defined(NDEBUG)
|
||||
#define DEBUG_ASSERT_NO_CLIENTAPI \
|
||||
FATAL_ERROR_IF(getClient(L) != nullptr, "Tried " \
|
||||
"to retrieve ServerEnvironment on client")
|
||||
#else
|
||||
#define DEBUG_ASSERT_NO_CLIENTAPI ((void)0)
|
||||
#endif
|
||||
|
||||
// Retrieve ServerEnvironment pointer as `env` (no map lock)
|
||||
#define GET_ENV_PTR_NO_MAP_LOCK \
|
||||
DEBUG_ASSERT_NO_CLIENTAPI; \
|
||||
ServerEnvironment *env = (ServerEnvironment *)getEnv(L); \
|
||||
if (env == NULL) \
|
||||
return 0
|
||||
|
||||
// Retrieve ServerEnvironment pointer as `env`
|
||||
#define GET_ENV_PTR \
|
||||
MAP_LOCK_REQUIRED; \
|
||||
GET_ENV_PTR_NO_MAP_LOCK
|
||||
|
||||
// Retrieve Environment pointer as `env` (no map lock)
|
||||
#define GET_PLAIN_ENV_PTR_NO_MAP_LOCK \
|
||||
Environment *env = (Environment *)getEnv(L); \
|
||||
if (env == NULL) \
|
||||
return 0
|
||||
|
||||
// Retrieve Environment pointer as `env`
|
||||
#define GET_PLAIN_ENV_PTR \
|
||||
MAP_LOCK_REQUIRED; \
|
||||
GET_PLAIN_ENV_PTR_NO_MAP_LOCK
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue