From 8658c8d9b5f30dc952eed29a19d619de9210474c Mon Sep 17 00:00:00 2001
From: Kahrl <kahrl@gmx.net>
Date: Tue, 25 Aug 2015 07:00:56 +0200
Subject: Use numeric indices and raw table access with LUA_REGISTRYINDEX

---
 src/script/common/c_internal.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

(limited to 'src/script/common')

diff --git a/src/script/common/c_internal.h b/src/script/common/c_internal.h
index ecb514c8f..80576b5e9 100644
--- a/src/script/common/c_internal.h
+++ b/src/script/common/c_internal.h
@@ -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) {                                 \
-- 
cgit v1.2.3