sdk-world
v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Toggle main menu visibility
Loading...
Searching...
No Matches
llimits.h
Go to the documentation of this file.
1
/*
2
** $Id: llimits.h $
3
** Limits, basic types, and some other 'installation-dependent' definitions
4
** See Copyright Notice in lua.h
5
*/
6
11
#ifndef llimits_h
12
#define llimits_h
13
14
15
#include <limits.h>
16
#include <stddef.h>
17
18
19
#include "
lua.h
"
20
21
22
/*
23
** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count
24
** the total memory used by Lua (in bytes). Usually, 'size_t' and
25
** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.
26
*/
27
#if defined(LUAI_MEM)
/* { external definitions? */
28
typedef
LUAI_UMEM lu_mem;
29
typedef
LUAI_MEM l_mem;
30
#elif LUAI_IS32INT
/* }{ */
31
typedef
size_t
lu_mem;
32
typedef
ptrdiff_t l_mem;
33
#else
/* 16-bit ints */
/* }{ */
34
typedef
unsigned
long
lu_mem;
35
typedef
long
l_mem;
36
#endif
/* } */
37
38
39
/* chars used as small naturals (so that 'char' is reserved for characters) */
40
typedef
unsigned
char
lu_byte;
41
typedef
signed
char
ls_byte;
42
43
44
/* maximum value for size_t */
45
#define MAX_SIZET ((size_t)(~(size_t)0))
46
47
/* maximum size visible for Lua (must be representable in a lua_Integer) */
48
#define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \
49
: (size_t)(LUA_MAXINTEGER))
50
51
52
#define MAX_LUMEM ((lu_mem)(~(lu_mem)0))
53
54
#define MAX_LMEM ((l_mem)(MAX_LUMEM >> 1))
55
56
57
#define MAX_INT INT_MAX
/* maximum value of an int */
58
59
60
/*
61
** 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.)
63
*/
64
#define log2maxs(t) (sizeof(t) * 8 - 2)
65
66
67
/*
68
** test whether an unsigned value is a power of 2 (or zero)
69
*/
70
#define ispow2(x) (((x) & ((x) - 1)) == 0)
71
72
73
/* number of chars of a literal string without the ending \0 */
74
#define LL(x) (sizeof(x)/sizeof(char) - 1)
75
76
77
/*
78
** conversion of pointer to unsigned integer: this is for hashing only;
79
** there is no problem if the integer cannot hold the whole pointer
80
** value. (In strict ISO C this may cause undefined behavior, but no
81
** actual machine seems to bother.)
82
*/
83
#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
84
__STDC_VERSION__ >= 199901L
85
#include <stdint.h>
86
#if defined(UINTPTR_MAX)
/* even in C99 this type is optional */
87
#define L_P2I uintptr_t
88
#else
/* no 'intptr'? */
89
#define L_P2I uintmax_t
/* use the largest available integer */
90
#endif
91
#else
/* C89 option */
92
#define L_P2I size_t
93
#endif
94
95
#define point2uint(p) ((unsigned int)((L_P2I)(p) & UINT_MAX))
96
97
98
99
/* types of 'usual argument conversions' for lua_Number and lua_Integer */
100
typedef
LUAI_UACNUMBER l_uacNumber;
101
typedef
LUAI_UACINT l_uacInt;
102
103
104
/*
105
** Internal assertions for in-house debugging
106
*/
107
#if defined LUAI_ASSERT
108
#undef NDEBUG
109
#include <assert.h>
110
#define lua_assert(c) assert(c)
111
#endif
112
113
#if defined(lua_assert)
114
#define check_exp(c,e) (lua_assert(c), (e))
115
/* to avoid problems with conditions too long */
116
#define lua_longassert(c) ((c) ? (void)0 : lua_assert(0))
117
#else
118
#define lua_assert(c) ((void)0)
119
#define check_exp(c,e) (e)
120
#define lua_longassert(c) ((void)0)
121
#endif
122
123
/*
124
** assertion for checking API calls
125
*/
126
#if !defined(luai_apicheck)
127
#define luai_apicheck(l,e) ((void)l, lua_assert(e))
128
#endif
129
130
#define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
131
132
133
/* macro to avoid warnings about unused variables */
134
#if !defined(UNUSED)
135
#define UNUSED(x) ((void)(x))
136
#endif
137
138
139
/* type casts (a macro highlights casts in the code) */
140
#define cast(t, exp) ((t)(exp))
141
142
#define cast_void(i) cast(void, (i))
143
#define cast_voidp(i) cast(void *, (i))
144
#define cast_num(i) cast(lua_Number, (i))
145
#define cast_int(i) cast(int, (i))
146
#define cast_uint(i) cast(unsigned int, (i))
147
#define cast_byte(i) cast(lu_byte, (i))
148
#define cast_uchar(i) cast(unsigned char, (i))
149
#define cast_char(i) cast(char, (i))
150
#define cast_charp(i) cast(char *, (i))
151
#define cast_sizet(i) cast(size_t, (i))
152
153
154
/* cast a signed lua_Integer to lua_Unsigned */
155
#if !defined(l_castS2U)
156
#define l_castS2U(i) ((lua_Unsigned)(i))
157
#endif
158
159
/*
160
** cast a lua_Unsigned to a signed lua_Integer; this cast is
161
** not strict ISO C, but two-complement architectures should
162
** work fine.
163
*/
164
#if !defined(l_castU2S)
165
#define l_castU2S(i) ((lua_Integer)(i))
166
#endif
167
168
169
/*
170
** non-return type
171
*/
172
#if !defined(l_noret)
173
174
#if defined(__GNUC__)
175
#define l_noret void __attribute__((noreturn))
176
#elif defined(_MSC_VER) && _MSC_VER >= 1200
177
#define l_noret void __declspec(noreturn)
178
#else
179
#define l_noret void
180
#endif
181
182
#endif
183
184
185
/*
186
** Inline functions
187
*/
188
#if !defined(LUA_USE_C89)
189
#define l_inline inline
190
#elif defined(__GNUC__)
191
#define l_inline __inline__
192
#else
193
#define l_inline
/* empty */
194
#endif
195
196
#define l_sinline static l_inline
197
198
199
/*
200
** type for virtual-machine instructions;
201
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
202
*/
203
#if LUAI_IS32INT
204
typedef
unsigned
int
l_uint32;
205
#else
206
typedef
unsigned
long
l_uint32;
207
#endif
208
209
typedef
l_uint32 Instruction;
210
211
212
213
/*
214
** Maximum length for short strings, that is, strings that are
215
** internalized. (Cannot be smaller than reserved words or tags for
216
** metamethods, as these strings must be internalized;
217
** #("function") = 8, #("__newindex") = 10.)
218
*/
219
#if !defined(LUAI_MAXSHORTLEN)
220
#define LUAI_MAXSHORTLEN 40
221
#endif
222
223
224
/*
225
** Initial size for the string table (must be power of 2).
226
** The Lua core alone registers ~50 strings (reserved words +
227
** metaevent keys + a few others). Libraries would typically add
228
** a few dozens more.
229
*/
230
#if !defined(MINSTRTABSIZE)
231
#define MINSTRTABSIZE 128
232
#endif
233
234
235
/*
236
** Size of cache for strings in the API. 'N' is the number of
237
** sets (better be a prime) and "M" is the size of each set (M == 1
238
** makes a direct cache.)
239
*/
240
#if !defined(STRCACHE_N)
241
#define STRCACHE_N 53
242
#define STRCACHE_M 2
243
#endif
244
245
246
/* minimum size for string buffer */
247
#if !defined(LUA_MINBUFFER)
248
#define LUA_MINBUFFER 32
249
#endif
250
251
252
/*
253
** Maximum depth for nested C calls, syntactical nested non-terminals,
254
** and other features implemented through recursion in C. (Value must
255
** fit in a 16-bit unsigned integer. It must also be compatible with
256
** the size of the C stack.)
257
*/
258
#if !defined(LUAI_MAXCCALLS)
259
#define LUAI_MAXCCALLS 200
260
#endif
261
262
263
/*
264
** macros that are executed whenever program enters the Lua core
265
** ('lua_lock') and leaves the core ('lua_unlock')
266
*/
267
#if !defined(lua_lock)
268
#define lua_lock(L) ((void) 0)
269
#define lua_unlock(L) ((void) 0)
270
#endif
271
272
/*
273
** macro executed during Lua functions at points where the
274
** function can yield.
275
*/
276
#if !defined(luai_threadyield)
277
#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
278
#endif
279
280
281
/*
282
** these macros allow user-specific actions when a thread is
283
** created/deleted/resumed/yielded.
284
*/
285
#if !defined(luai_userstateopen)
286
#define luai_userstateopen(L) ((void)L)
287
#endif
288
289
#if !defined(luai_userstateclose)
290
#define luai_userstateclose(L) ((void)L)
291
#endif
292
293
#if !defined(luai_userstatethread)
294
#define luai_userstatethread(L,L1) ((void)L)
295
#endif
296
297
#if !defined(luai_userstatefree)
298
#define luai_userstatefree(L,L1) ((void)L)
299
#endif
300
301
#if !defined(luai_userstateresume)
302
#define luai_userstateresume(L,n) ((void)L)
303
#endif
304
305
#if !defined(luai_userstateyield)
306
#define luai_userstateyield(L,n) ((void)L)
307
#endif
308
309
310
311
/*
312
** The luai_num* macros define the primitive operations over numbers.
313
*/
314
315
/* floor division (defined as 'floor(a/b)') */
316
#if !defined(luai_numidiv)
317
#define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b)))
318
#endif
319
320
/* float division */
321
#if !defined(luai_numdiv)
322
#define luai_numdiv(L,a,b) ((a)/(b))
323
#endif
324
325
/*
326
** modulo: defined as 'a - floor(a/b)*b'; the direct computation
327
** using this definition has several problems with rounding errors,
328
** so it is better to use 'fmod'. 'fmod' gives the result of
329
** 'a - trunc(a/b)*b', and therefore must be corrected when
330
** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a
331
** non-integer negative result: non-integer result is equivalent to
332
** a non-zero remainder 'm'; negative result is equivalent to 'a' and
333
** 'b' with different signs, or 'm' and 'b' with different signs
334
** (as the result 'm' of 'fmod' has the same sign of 'a').
335
*/
336
#if !defined(luai_nummod)
337
#define luai_nummod(L,a,b,m) \
338
{ (void)L; (m) = l_mathop(fmod)(a,b); \
339
if (((m) > 0) ? (b) < 0 : ((m) < 0 && (b) > 0)) (m) += (b); }
340
#endif
341
342
/* exponentiation */
343
#if !defined(luai_numpow)
344
#define luai_numpow(L,a,b) \
345
((void)L, (b == 2) ? (a)*(a) : l_mathop(pow)(a,b))
346
#endif
347
348
/* the others are quite standard operations */
349
#if !defined(luai_numadd)
350
#define luai_numadd(L,a,b) ((a)+(b))
351
#define luai_numsub(L,a,b) ((a)-(b))
352
#define luai_nummul(L,a,b) ((a)*(b))
353
#define luai_numunm(L,a) (-(a))
354
#define luai_numeq(a,b) ((a)==(b))
355
#define luai_numlt(a,b) ((a)<(b))
356
#define luai_numle(a,b) ((a)<=(b))
357
#define luai_numgt(a,b) ((a)>(b))
358
#define luai_numge(a,b) ((a)>=(b))
359
#define luai_numisnan(a) (!luai_numeq((a), (a)))
360
#endif
361
362
363
364
365
366
/*
367
** macro to control inclusion of some hard tests on stack reallocation
368
*/
369
#if !defined(HARDSTACKTESTS)
370
#define condmovestack(L,pre,pos) ((void)0)
371
#else
372
/* realloc stack keeping its size */
373
#define condmovestack(L,pre,pos) \
374
{ int sz_ = stacksize(L); pre; luaD_reallocstack((L), sz_, 0); pos; }
375
#endif
376
377
#if !defined(HARDMEMTESTS)
378
#define condchangemem(L,pre,pos) ((void)0)
379
#else
380
#define condchangemem(L,pre,pos) \
381
{ if (gcrunning(G(L))) { pre; luaC_fullgc(L, 0); pos; } }
382
#endif
383
384
#endif
lua.h
lua
src
llimits.h
Generated by
1.18.0