diff options
Diffstat (limited to '')
-rw-r--r-- | llimits.h | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -15,6 +15,8 @@ | |||
15 | #include "lua.h" | 15 | #include "lua.h" |
16 | 16 | ||
17 | 17 | ||
18 | #define l_numbits(t) cast_int(sizeof(t) * CHAR_BIT) | ||
19 | |||
18 | /* | 20 | /* |
19 | ** 'l_mem' is a signed integer big enough to count the total memory | 21 | ** 'l_mem' is a signed integer big enough to count the total memory |
20 | ** used by Lua. (It is signed due to the use of debt in several | 22 | ** used by Lua. (It is signed due to the use of debt in several |
@@ -33,7 +35,7 @@ typedef unsigned long lu_mem; | |||
33 | #endif /* } */ | 35 | #endif /* } */ |
34 | 36 | ||
35 | #define MAX_LMEM \ | 37 | #define MAX_LMEM \ |
36 | cast(l_mem, (cast(lu_mem, 1) << (sizeof(l_mem) * 8 - 1)) - 1) | 38 | cast(l_mem, (cast(lu_mem, 1) << (l_numbits(l_mem) - 1)) - 1) |
37 | 39 | ||
38 | 40 | ||
39 | /* chars used as small naturals (so that 'char' is reserved for characters) */ | 41 | /* chars used as small naturals (so that 'char' is reserved for characters) */ |
@@ -61,7 +63,7 @@ typedef lu_byte TStatus; | |||
61 | ** floor of the log2 of the maximum signed value for integral type 't'. | 63 | ** floor of the log2 of the maximum signed value for integral type 't'. |
62 | ** (That is, maximum 'n' such that '2^n' fits in the given signed type.) | 64 | ** (That is, maximum 'n' such that '2^n' fits in the given signed type.) |
63 | */ | 65 | */ |
64 | #define log2maxs(t) cast_int(sizeof(t) * 8 - 2) | 66 | #define log2maxs(t) (l_numbits(t) - 2) |
65 | 67 | ||
66 | 68 | ||
67 | /* | 69 | /* |
@@ -135,13 +137,15 @@ typedef LUAI_UACINT l_uacInt; | |||
135 | #define cast_voidp(i) cast(void *, (i)) | 137 | #define cast_voidp(i) cast(void *, (i)) |
136 | #define cast_num(i) cast(lua_Number, (i)) | 138 | #define cast_num(i) cast(lua_Number, (i)) |
137 | #define cast_int(i) cast(int, (i)) | 139 | #define cast_int(i) cast(int, (i)) |
140 | #define cast_short(i) cast(short, (i)) | ||
138 | #define cast_uint(i) cast(unsigned int, (i)) | 141 | #define cast_uint(i) cast(unsigned int, (i)) |
139 | #define cast_ulong(i) cast(unsigned long, (i)) | ||
140 | #define cast_byte(i) cast(lu_byte, (i)) | 142 | #define cast_byte(i) cast(lu_byte, (i)) |
141 | #define cast_uchar(i) cast(unsigned char, (i)) | 143 | #define cast_uchar(i) cast(unsigned char, (i)) |
142 | #define cast_char(i) cast(char, (i)) | 144 | #define cast_char(i) cast(char, (i)) |
143 | #define cast_charp(i) cast(char *, (i)) | 145 | #define cast_charp(i) cast(char *, (i)) |
144 | #define cast_sizet(i) cast(size_t, (i)) | 146 | #define cast_sizet(i) cast(size_t, (i)) |
147 | #define cast_Integer(i) cast(lua_Integer, (i)) | ||
148 | #define cast_Inst(i) cast(Instruction, (i)) | ||
145 | 149 | ||
146 | 150 | ||
147 | /* cast a signed lua_Integer to lua_Unsigned */ | 151 | /* cast a signed lua_Integer to lua_Unsigned */ |