1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Use numeric indices and raw table access with LUA_REGISTRYINDEX

This commit is contained in:
Kahrl 2015-08-25 07:00:56 +02:00 committed by est31
parent 34b7a147dc
commit 8658c8d9b5
7 changed files with 36 additions and 16 deletions

View file

@ -34,6 +34,27 @@ extern "C" {
#include "common/c_types.h"
/*
Define our custom indices into the Lua registry table.
Lua 5.2 and above define the LUA_RIDX_LAST macro. Only numbers above that
may be used for custom indices, anything else is reserved.
Lua 5.1 / LuaJIT do not use any numeric indices (only string indices),
so we can use numeric indices freely.
*/
#ifdef LUA_RIDX_LAST
#define CUSTOM_RIDX_BASE ((LUA_RIDX_LAST)+1)
#else
#define CUSTOM_RIDX_BASE 1
#endif
#define CUSTOM_RIDX_SCRIPTAPI (CUSTOM_RIDX_BASE)
#define CUSTOM_RIDX_GLOBALS_BACKUP (CUSTOM_RIDX_BASE + 1)
#define CUSTOM_RIDX_CURRENT_MOD_NAME (CUSTOM_RIDX_BASE + 2)
#define PCALL_RESL(L, RES) do { \
int result_ = (RES); \
if (result_ != 0) { \