|
30 | 30 | #define IS_INT64_EQUIVALENT(x) IS_INT_TYPE_EQUIVALENT(x, int64_t)
|
31 | 31 | #define IS_INT_EQUIVALENT(x) IS_INT_TYPE_EQUIVALENT(x, int)
|
32 | 32 |
|
| 33 | +/* If size of pointer is equal to a 4 byte integer, we're on 32 bits. */ |
| 34 | +#if UINTPTR_MAX == UINT_MAX |
| 35 | + #define BITS_32 1 |
| 36 | +#else |
| 37 | + #define BITS_32 0 |
| 38 | +#endif |
| 39 | + |
33 | 40 | #if LUA_VERSION_NUM < 503
|
34 |
| - #define lua_pushunsigned(L, n) lua_pushinteger(L, n) |
| 41 | + #if BITS_32 |
| 42 | + #define lua_pushunsigned(L, n) lua_pushnumber(L, n) |
| 43 | + #else |
| 44 | + #define lua_pushunsigned(L, n) lua_pushinteger(L, n) |
| 45 | + #endif |
35 | 46 | #endif
|
36 | 47 |
|
37 | 48 | /* =============================================================================
|
@@ -348,7 +359,11 @@ static void mp_encode_lua_bool(lua_State *L, mp_buf *buf) {
|
348 | 359 |
|
349 | 360 | /* Lua 5.3 has a built in 64-bit integer type */
|
350 | 361 | static void mp_encode_lua_integer(lua_State *L, mp_buf *buf) {
|
| 362 | +#if (LUA_VERSION_NUM < 503) && BITS_32 |
| 363 | + lua_Number i = lua_tonumber(L,-1); |
| 364 | +#else |
351 | 365 | lua_Integer i = lua_tointeger(L,-1);
|
| 366 | +#endif |
352 | 367 | mp_encode_int(buf, (int64_t)i);
|
353 | 368 | }
|
354 | 369 |
|
@@ -431,10 +446,11 @@ static int table_is_an_array(lua_State *L) {
|
431 | 446 | /* The <= 0 check is valid here because we're comparing indexes. */
|
432 | 447 | #if LUA_VERSION_NUM < 503
|
433 | 448 | if ((LUA_TNUMBER != lua_type(L,-1)) || (n = lua_tonumber(L, -1)) <= 0 ||
|
434 |
| - !IS_INT_EQUIVALENT(n)) { |
| 449 | + !IS_INT_EQUIVALENT(n)) |
435 | 450 | #else
|
436 |
| - if (!lua_isinteger(L,-1) || (n = lua_tointeger(L, -1)) <= 0) { |
| 451 | + if (!lua_isinteger(L,-1) || (n = lua_tointeger(L, -1)) <= 0) |
437 | 452 | #endif
|
| 453 | + { |
438 | 454 | lua_settop(L, stacktop);
|
439 | 455 | return 0;
|
440 | 456 | }
|
@@ -628,7 +644,11 @@ void mp_decode_to_lua_type(lua_State *L, mp_cur *c) {
|
628 | 644 | break;
|
629 | 645 | case 0xd3: /* int 64 */
|
630 | 646 | mp_cur_need(c,9);
|
| 647 | +#if LUA_VERSION_NUM < 503 |
| 648 | + lua_pushnumber(L, |
| 649 | +#else |
631 | 650 | lua_pushinteger(L,
|
| 651 | +#endif |
632 | 652 | ((int64_t)c->p[1] << 56) |
|
633 | 653 | ((int64_t)c->p[2] << 48) |
|
634 | 654 | ((int64_t)c->p[3] << 40) |
|
|
0 commit comments