From 0690a7d181c4a0519b3c45ee9b5db789c2466903 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Wed, 25 Aug 2021 18:58:53 +1000 Subject: [PATCH] Make bit module handle 32/64bit integer configs. --- components/lua/lua-5.1/luaconf.h | 2 +- components/modules/bit.c | 8 +++++--- docs/modules/bit.md | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/components/lua/lua-5.1/luaconf.h b/components/lua/lua-5.1/luaconf.h index fc78d2ef..2a9bbcf8 100644 --- a/components/lua/lua-5.1/luaconf.h +++ b/components/lua/lua-5.1/luaconf.h @@ -169,7 +169,7 @@ /* Changed to long for use with integral Lua numbers. */ #if !defined LUA_NUMBER_INTEGRAL -#define LUA_INTEGER ptrdiff_t +#define LUA_INTEGER int #else #if !defined LUA_INTEGRAL_LONGLONG #define LUA_INTEGER int diff --git a/components/modules/bit.c b/components/modules/bit.c index c5dafd69..cd28f44d 100644 --- a/components/modules/bit.c +++ b/components/modules/bit.c @@ -10,9 +10,11 @@ #include "lauxlib.h" -/* FIXME: Assume size_t is an unsigned lua_Integer */ -typedef size_t lua_UInteger; -#define LUA_UINTEGER_MAX SIZE_MAX +#if defined(LUA_UNSIGNED) +typedef LUA_UNSIGNED lua_UInteger; +#else +typedef unsigned LUA_INTEGER lua_UInteger; +#endif /* Define TOBIT to get a bit value */ #define TOBIT(L, n) \ diff --git a/docs/modules/bit.md b/docs/modules/bit.md index cc406763..5e20c6b9 100644 --- a/docs/modules/bit.md +++ b/docs/modules/bit.md @@ -4,7 +4,9 @@ | 2014-12-24 | [https://github.com/LuaDist/bitlib](https://github.com/LuaDist/bitlib), [Zeroday](https://github.com/funshine) | [Zeroday](https://github.com/funshine) | [bit.c](../../components/modules/bit.c)| -Bit manipulation support, on 32bit integers. +Bit manipulation support, on the integer type used by the Lua VM. On 5.1 this +will be 32bit, whereas on 5.3 it may be either 32bit (default) or 64bit if +configured for 64bit integers. ## bit.arshift() Arithmetic right shift a number equivalent to `value >> shift` in C.