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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
Author: Andrew Engelbrecht
Description: Port to Lua 5.3 and 5.4
See https://github.com/LuaJIT/LuaJIT/issues/384 for details.
Last-Modified: Fri, 27 Jan 2023 15:40:02 +0300
--- a/bit.c
+++ b/bit.c
@@ -32,8 +32,8 @@
#include "lua.h"
#include "lauxlib.h"
-#ifdef _MSC_VER
-/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */
+#if defined(_MSC_VER) && (_MSC_VER < 1700)
+/* Old MSVC is stuck in the last century and doesn't have C99's stdint.h. */
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
@@ -46,7 +46,7 @@
typedef union {
lua_Number n;
-#ifdef LUA_NUMBER_DOUBLE
+#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE)
uint64_t b;
#else
UBits b;
@@ -63,24 +63,25 @@
#else
bn.n = luaL_checknumber(L, idx);
#endif
-#if defined(LUA_NUMBER_DOUBLE)
+#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE)
bn.n += 6755399441055744.0; /* 2^52+2^51 */
#ifdef SWAPPED_DOUBLE
b = (UBits)(bn.b >> 32);
#else
b = (UBits)bn.b;
#endif
-#elif defined(LUA_NUMBER_INT) || defined(LUA_NUMBER_LONG) || \
- defined(LUA_NUMBER_LONGLONG) || defined(LUA_NUMBER_LONG_LONG) || \
- defined(LUA_NUMBER_LLONG)
+#elif defined(LUA_NUMBER_INT) || defined(LUA_INT_INT) || \
+ defined(LUA_NUMBER_LONG) || defined(LUA_INT_LONG) || \
+ defined(LUA_NUMBER_LONGLONG) || defined(LUA_INT_LONGLONG) || \
+ defined(LUA_NUMBER_LONG_LONG) || defined(LUA_NUMBER_LLONG)
if (sizeof(UBits) == sizeof(lua_Number))
b = bn.b;
else
b = (UBits)(SBits)bn.n;
-#elif defined(LUA_NUMBER_FLOAT)
+#elif defined(LUA_NUMBER_FLOAT) || defined(LUA_FLOAT_FLOAT)
#error "A 'float' lua_Number type is incompatible with this library"
#else
-#error "Unknown number type, check LUA_NUMBER_* in luaconf.h"
+#error "Unknown number type, check LUA_NUMBER_*, LUA_FLOAT_*, LUA_INT_* in luaconf.h"
#endif
#if LUA_VERSION_NUM < 502
if (b == 0 && !lua_isnumber(L, idx)) {
@@ -91,7 +92,11 @@
}
/* Return bit type. */
+#if LUA_VERSION_NUM < 503
#define BRET(b) lua_pushnumber(L, (lua_Number)(SBits)(b)); return 1;
+#else
+#define BRET(b) lua_pushinteger(L, (lua_Integer)(SBits)(b)); return 1;
+#endif
static int bit_tobit(lua_State *L) { BRET(barg(L, 1)) }
static int bit_bnot(lua_State *L) { BRET(~barg(L, 1)) }
@@ -163,11 +168,15 @@
LUALIB_API int luaopen_bit(lua_State *L)
{
UBits b;
+#if LUA_VERSION_NUM < 503
lua_pushnumber(L, (lua_Number)1437217655L);
+#else
+ lua_pushinteger(L, (lua_Integer)1437217655L);
+#endif
b = barg(L, -1);
if (b != (UBits)1437217655L || BAD_SAR) { /* Perform a simple self-test. */
const char *msg = "compiled with incompatible luaconf.h";
-#ifdef LUA_NUMBER_DOUBLE
+#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE)
#ifdef _WIN32
if (b == (UBits)1610612736L)
msg = "use D3DCREATE_FPU_PRESERVE with DirectX";
|