|
@@ -123,6 +123,10 @@ static bool supports_full_lightuserdata(lua_State *L)
|
|
|
static bool checked = false;
|
|
|
static bool supported = false;
|
|
|
|
|
|
+ if (sizeof(void*) == 4)
|
|
|
+ // 32-bit platforms always supports full-lightuserdata.
|
|
|
+ return true;
|
|
|
+
|
|
|
if (!checked)
|
|
|
{
|
|
|
lua_pushcclosure(L, [](lua_State* L) -> int
|
|
@@ -168,13 +172,16 @@ static uintptr_t compute_peer_key(lua_State *L, ENetPeer *peer)
|
|
|
|
|
|
static void push_peer_key(lua_State *L, uintptr_t key)
|
|
|
{
|
|
|
- // If full 64-bit lightuserdata is supported, always use that. Otherwise,
|
|
|
- // if the key is smaller than 2^53 (which is integer precision for double
|
|
|
- // datatype), then push number. Otherwise, throw error.
|
|
|
+ // If full 64-bit lightuserdata is supported (or it's 32-bit platform),
|
|
|
+ // always use that. Otherwise, if the key is smaller than 2^53 (which is
|
|
|
+ // integer precision for double datatype) on 64-bit platform, then push
|
|
|
+ // number. Otherwise, throw error.
|
|
|
if (supports_full_lightuserdata(L))
|
|
|
lua_pushlightuserdata(L, (void*) key);
|
|
|
+#if UINTPTR_MAX == 0xffffffffffffffff
|
|
|
else if (key > 0x20000000000000ULL) // 2^53
|
|
|
luaL_error(L, "Cannot push enet peer to Lua: pointer value %p is too large", key);
|
|
|
+#endif
|
|
|
else
|
|
|
lua_pushnumber(L, (lua_Number) key);
|
|
|
}
|