1616
1717#include " lua.h"
1818
19-
20- #define l_numbits (t ) cast_int(sizeof (t) * CHAR_BIT)
21-
2219/*
2320** 'l_mem' is a signed integer big enough to count the total memory
2421** used by Lua. (It is signed due to the use of debt in several
@@ -36,8 +33,7 @@ typedef long l_mem;
3633typedef unsigned long lu_mem;
3734#endif /* } */
3835
39- #define MAX_LMEM \
40- cast (l_mem, (cast(lu_mem, 1 ) << (l_numbits(l_mem) - 1)) - 1)
36+ /* MAX_LMEM defined later in this file after cast functions and l_numbits */
4137
4238
4339/* chars used as small naturals (so that 'char' is reserved for characters) */
@@ -57,15 +53,13 @@ inline constexpr size_t MAX_SIZET = ((size_t)(~(size_t)0));
5753/*
5854** Maximum size for strings and userdata visible for Lua; should be
5955** representable as a lua_Integer and as a size_t.
56+ ** Defined later in this file after cast functions.
6057*/
61- #define MAX_SIZE (sizeof (size_t ) < sizeof (lua_Integer) ? MAX_SIZET \
62- : cast_sizet(LUA_MAXINTEGER))
6358
64- /*
65- ** floor of the log2 of the maximum signed value for integral type 't'.
59+ /* floor of the log2 of the maximum signed value for integral type 't'.
6660** (That is, maximum 'n' such that '2^n' fits in the given signed type.)
61+ ** Defined later in this file after cast functions.
6762*/
68- #define log2maxs (t ) (l_numbits(t) - 2 )
6963
7064
7165/*
@@ -236,6 +230,25 @@ inline constexpr unsigned int point2uint(T* p) noexcept {
236230 return cast_uint ((L_P2I)(p) & std::numeric_limits<unsigned int >::max ());
237231}
238232
233+ /* Phase 126.1: Converted l_numbits from macro to template constexpr function */
234+ template <typename T>
235+ inline constexpr int l_numbits () noexcept {
236+ return cast_int (sizeof (T) * CHAR_BIT);
237+ }
238+
239+ /* Phase 126.1: Converted log2maxs from macro to template constexpr function */
240+ template <typename T>
241+ inline constexpr int log2maxs () noexcept {
242+ return l_numbits<T>() - 2 ;
243+ }
244+
245+ /* Phase 126.1: Converted MAX_SIZE from macro to inline constexpr (moved here after dependencies) */
246+ inline constexpr size_t MAX_SIZE = (sizeof (size_t ) < sizeof(lua_Integer) ? MAX_SIZET
247+ : cast_sizet(LUA_MAXINTEGER));
248+
249+ /* Phase 126.1: Converted MAX_LMEM from macro to inline constexpr (moved here after dependencies) */
250+ inline constexpr l_mem MAX_LMEM = cast(l_mem, (cast(lu_mem, 1 ) << (l_numbits<l_mem>() - 1 )) - 1 );
251+
239252
240253/* cast a signed lua_Integer to lua_Unsigned */
241254#if !defined(l_castS2U)
0 commit comments