diff options
author | Benoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m> | 2018-10-30 14:18:10 +0100 |
---|---|---|
committer | Benoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m> | 2018-10-30 14:18:10 +0100 |
commit | d82bf70e9db3a25ec451b599660f3a837f21caee (patch) | |
tree | e9e861252a118c8c66e874fedb93c2a32733aa0f /src/uniquekey.h | |
parent | ea9e8a3af1c2357c454ef18c8136c14a22b8675a (diff) | |
download | lanes-d82bf70e9db3a25ec451b599660f3a837f21caee.tar.gz lanes-d82bf70e9db3a25ec451b599660f3a837f21caee.tar.bz2 lanes-d82bf70e9db3a25ec451b599660f3a837f21caee.zip |
Improve LuaJIT-x64 compatibility
Restrict internal "light userdata constants" to 47 significant bits when
compiling against LuaJIT-x64
Diffstat (limited to 'src/uniquekey.h')
-rw-r--r-- | src/uniquekey.h | 25 |
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. | ||
7 | struct s_UniqueKey | ||
8 | { | ||
9 | void* value; | ||
10 | }; | ||
11 | typedef 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__ | ||