aboutsummaryrefslogtreecommitdiff
path: root/src/uniquekey.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/uniquekey.h')
-rw-r--r--src/uniquekey.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/uniquekey.h b/src/uniquekey.h
new file mode 100644
index 0000000..c90d09a
--- /dev/null
+++ b/src/uniquekey.h
@@ -0,0 +1,25 @@
1#if !defined __LANES_UNIQUEKEY_H__
2#define __LANES_UNIQUEKEY_H__ 1
3
4#include "lualib.h"
5
6// Lua light userdata can hold a pointer.
7struct s_UniqueKey
8{
9 void* value;
10};
11typedef struct s_UniqueKey UniqueKey;
12
13#if defined(LUA_JITLIBNAME) && (defined(__x86_64__) || defined(_M_X64)) // building against LuaJIT headers, light userdata is restricted to 47 significant bits.
14#define MAKE_UNIQUE_KEY( p_) ((void*)(p_) & 0x7fffffffffffull)
15#else // LUA_JITLIBNAME
16#define MAKE_UNIQUE_KEY( p_) ((void*) p_)
17#endif // LUA_JITLIBNAME
18
19#define DECLARE_UNIQUE_KEY( name_) UniqueKey name_
20#define DECLARE_CONST_UNIQUE_KEY( name_, p_) UniqueKey const name_ = { MAKE_UNIQUE_KEY( p_)}
21
22#define push_unique_key( L, key_) lua_pushlightuserdata( L, key_.value)
23#define equal_unique_key( L, i, key_) (lua_touserdata( L, i) == key_.value)
24
25#endif // __LANES_UNIQUEKEY_H__