blob: 015fbf239be33ad0dac7c06f534f043f7229e7af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#if !defined __LANES_UNIQUEKEY_H__
#define __LANES_UNIQUEKEY_H__ 1
#include "compat.h"
// Lua light userdata can hold a pointer.
struct s_UniqueKey
{
void* value;
};
typedef struct s_UniqueKey UniqueKey;
#if LUAJIT_FLAVOR() == 64 // building against LuaJIT headers for 64 bits, light userdata is restricted to 47 significant bits, because LuaJIT uses the other bits for internal optimizations
#define MAKE_UNIQUE_KEY( p_) ((void*)((ptrdiff_t)(p_) & 0x7fffffffffffull))
#else // LUAJIT_FLAVOR()
#define MAKE_UNIQUE_KEY( p_) ((void*)(ptrdiff_t)(p_))
#endif // LUAJIT_FLAVOR()
#define DECLARE_UNIQUE_KEY( name_) UniqueKey name_
#define DECLARE_CONST_UNIQUE_KEY( name_, p_) UniqueKey const name_ = { MAKE_UNIQUE_KEY( p_)}
#define push_unique_key( L, key_) lua_pushlightuserdata( L, key_.value)
#define equal_unique_key( L, i, key_) (lua_touserdata( L, i) == key_.value)
#endif // __LANES_UNIQUEKEY_H__
|