sdk-world
v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Toggle main menu visibility
Loading...
Searching...
No Matches
lobject.h
Go to the documentation of this file.
1
/*
2
** $Id: lobject.h $
3
** Type definitions for Lua objects
4
** See Copyright Notice in lua.h
5
*/
6
7
12
#ifndef lobject_h
13
#define lobject_h
14
15
16
#include <stdarg.h>
17
18
19
#include "
llimits.h
"
20
#include "
lua.h
"
21
22
23
/*
24
** Extra types for collectable non-values
25
*/
26
#define LUA_TUPVAL LUA_NUMTYPES
/* upvalues */
27
#define LUA_TPROTO (LUA_NUMTYPES+1)
/* function prototypes */
28
#define LUA_TDEADKEY (LUA_NUMTYPES+2)
/* removed keys in tables */
29
30
31
32
/*
33
** number of all possible types (including LUA_TNONE but excluding DEADKEY)
34
*/
35
#define LUA_TOTALTYPES (LUA_TPROTO + 2)
36
37
38
/*
39
** tags for Tagged Values have the following use of bits:
40
** bits 0-3: actual tag (a LUA_T* constant)
41
** bits 4-5: variant bits
42
** bit 6: whether value is collectable
43
*/
44
45
/* add variant bits to a type */
46
#define makevariant(t,v) ((t) | ((v) << 4))
47
48
49
50
/*
51
** Union of all Lua values
52
*/
53
typedef
union
Value
{
54
struct
GCObject
*gc;
/* collectable objects */
55
void
*p;
/* light userdata */
56
lua_CFunction f;
/* light C functions */
57
lua_Integer i;
/* integer numbers */
58
lua_Number n;
/* float numbers */
59
/* not used, but may avoid warnings for uninitialized value */
60
lu_byte ub;
61
}
Value
;
62
63
64
/*
65
** Tagged Values. This is the basic representation of values in Lua:
66
** an actual value plus a tag with its type.
67
*/
68
69
#define TValuefields Value value_; lu_byte tt_
70
71
typedef
struct
TValue
{
72
TValuefields;
73
}
TValue
;
74
75
76
#define val_(o) ((o)->value_)
77
#define valraw(o) (val_(o))
78
79
80
/* raw type tag of a TValue */
81
#define rawtt(o) ((o)->tt_)
82
83
/* tag with no variants (bits 0-3) */
84
#define novariant(t) ((t) & 0x0F)
85
86
/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
87
#define withvariant(t) ((t) & 0x3F)
88
#define ttypetag(o) withvariant(rawtt(o))
89
90
/* type of a TValue */
91
#define ttype(o) (novariant(rawtt(o)))
92
93
94
/* Macros to test type */
95
#define checktag(o,t) (rawtt(o) == (t))
96
#define checktype(o,t) (ttype(o) == (t))
97
98
99
/* Macros for internal tests */
100
101
/* collectable object has the same tag as the original value */
102
#define righttt(obj) (ttypetag(obj) == gcvalue(obj)->tt)
103
104
/*
105
** Any value being manipulated by the program either is non
106
** collectable, or the collectable object has the right tag
107
** and it is not dead. The option 'L == NULL' allows other
108
** macros using this one to be used where L is not available.
109
*/
110
#define checkliveness(L,obj) \
111
((void)L, lua_longassert(!iscollectable(obj) || \
112
(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj))))))
113
114
115
/* Macros to set values */
116
117
/* set a value's tag */
118
#define settt_(o,t) ((o)->tt_=(t))
119
120
121
/* main macro to copy values (from 'obj2' to 'obj1') */
122
#define setobj(L,obj1,obj2) \
123
{ TValue *io1=(obj1); const TValue *io2=(obj2); \
124
io1->value_ = io2->value_; settt_(io1, io2->tt_); \
125
checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); }
126
127
/*
128
** Different types of assignments, according to source and destination.
129
** (They are mostly equal now, but may be different in the future.)
130
*/
131
132
/* from stack to stack */
133
#define setobjs2s(L,o1,o2) setobj(L,s2v(o1),s2v(o2))
134
/* to stack (not from same stack) */
135
#define setobj2s(L,o1,o2) setobj(L,s2v(o1),o2)
136
/* from table to same table */
137
#define setobjt2t setobj
138
/* to new object */
139
#define setobj2n setobj
140
/* to table */
141
#define setobj2t setobj
142
143
144
/*
145
** Entries in a Lua stack. Field 'tbclist' forms a list of all
146
** to-be-closed variables active in this stack. Dummy entries are
147
** used when the distance between two tbc variables does not fit
148
** in an unsigned short. They are represented by delta==0, and
149
** their real delta is always the maximum value that fits in
150
** that field.
151
*/
152
typedef
union
StackValue
{
153
TValue
val;
154
struct
{
155
TValuefields;
156
unsigned
short
delta;
157
} tbclist;
158
}
StackValue
;
159
160
161
/* index to stack elements */
162
typedef
StackValue
*StkId;
163
164
165
/*
166
** When reallocating the stack, change all pointers to the stack into
167
** proper offsets.
168
*/
169
typedef
union
{
170
StkId p;
/* actual pointer */
171
ptrdiff_t offset;
/* used while the stack is being reallocated */
172
}
StkIdRel
;
173
174
175
/* convert a 'StackValue' to a 'TValue' */
176
#define s2v(o) (&(o)->val)
177
178
179
180
/*
181
** {==================================================================
182
** Nil
183
** ===================================================================
184
*/
185
186
/* Standard nil */
187
#define LUA_VNIL makevariant(LUA_TNIL, 0)
188
189
/* Empty slot (which might be different from a slot containing nil) */
190
#define LUA_VEMPTY makevariant(LUA_TNIL, 1)
191
192
/* Value returned for a key not found in a table (absent key) */
193
#define LUA_VABSTKEY makevariant(LUA_TNIL, 2)
194
195
196
/* macro to test for (any kind of) nil */
197
#define ttisnil(v) checktype((v), LUA_TNIL)
198
199
200
/* macro to test for a standard nil */
201
#define ttisstrictnil(o) checktag((o), LUA_VNIL)
202
203
204
#define setnilvalue(obj) settt_(obj, LUA_VNIL)
205
206
207
#define isabstkey(v) checktag((v), LUA_VABSTKEY)
208
209
210
/*
211
** macro to detect non-standard nils (used only in assertions)
212
*/
213
#define isnonstrictnil(v) (ttisnil(v) && !ttisstrictnil(v))
214
215
216
/*
217
** By default, entries with any kind of nil are considered empty.
218
** (In any definition, values associated with absent keys must also
219
** be accepted as empty.)
220
*/
221
#define isempty(v) ttisnil(v)
222
223
224
/* macro defining a value corresponding to an absent key */
225
#define ABSTKEYCONSTANT {NULL}, LUA_VABSTKEY
226
227
228
/* mark an entry as empty */
229
#define setempty(v) settt_(v, LUA_VEMPTY)
230
231
232
233
/* }================================================================== */
234
235
236
/*
237
** {==================================================================
238
** Booleans
239
** ===================================================================
240
*/
241
242
243
#define LUA_VFALSE makevariant(LUA_TBOOLEAN, 0)
244
#define LUA_VTRUE makevariant(LUA_TBOOLEAN, 1)
245
246
#define ttisboolean(o) checktype((o), LUA_TBOOLEAN)
247
#define ttisfalse(o) checktag((o), LUA_VFALSE)
248
#define ttistrue(o) checktag((o), LUA_VTRUE)
249
250
251
#define l_isfalse(o) (ttisfalse(o) || ttisnil(o))
252
253
254
#define setbfvalue(obj) settt_(obj, LUA_VFALSE)
255
#define setbtvalue(obj) settt_(obj, LUA_VTRUE)
256
257
/* }================================================================== */
258
259
260
/*
261
** {==================================================================
262
** Threads
263
** ===================================================================
264
*/
265
266
#define LUA_VTHREAD makevariant(LUA_TTHREAD, 0)
267
268
#define ttisthread(o) checktag((o), ctb(LUA_VTHREAD))
269
270
#define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc))
271
272
#define setthvalue(L,obj,x) \
273
{ TValue *io = (obj); lua_State *x_ = (x); \
274
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTHREAD)); \
275
checkliveness(L,io); }
276
277
#define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t)
278
279
/* }================================================================== */
280
281
282
/*
283
** {==================================================================
284
** Collectable Objects
285
** ===================================================================
286
*/
287
288
/*
289
** Common Header for all collectable objects (in macro form, to be
290
** included in other objects)
291
*/
292
#define CommonHeader struct GCObject *next; lu_byte tt; lu_byte marked
293
294
295
/* Common type for all collectable objects */
296
typedef
struct
GCObject
{
297
CommonHeader;
298
}
GCObject
;
299
300
301
/* Bit mark for collectable types */
302
#define BIT_ISCOLLECTABLE (1 << 6)
303
304
#define iscollectable(o) (rawtt(o) & BIT_ISCOLLECTABLE)
305
306
/* mark a tag as collectable */
307
#define ctb(t) ((t) | BIT_ISCOLLECTABLE)
308
309
#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
310
311
#define gcvalueraw(v) ((v).gc)
312
313
#define setgcovalue(L,obj,x) \
314
{ TValue *io = (obj); GCObject *i_g=(x); \
315
val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }
316
317
/* }================================================================== */
318
319
320
/*
321
** {==================================================================
322
** Numbers
323
** ===================================================================
324
*/
325
326
/* Variant tags for numbers */
327
#define LUA_VNUMINT makevariant(LUA_TNUMBER, 0)
/* integer numbers */
328
#define LUA_VNUMFLT makevariant(LUA_TNUMBER, 1)
/* float numbers */
329
330
#define ttisnumber(o) checktype((o), LUA_TNUMBER)
331
#define ttisfloat(o) checktag((o), LUA_VNUMFLT)
332
#define ttisinteger(o) checktag((o), LUA_VNUMINT)
333
334
#define nvalue(o) check_exp(ttisnumber(o), \
335
(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))
336
#define fltvalue(o) check_exp(ttisfloat(o), val_(o).n)
337
#define ivalue(o) check_exp(ttisinteger(o), val_(o).i)
338
339
#define fltvalueraw(v) ((v).n)
340
#define ivalueraw(v) ((v).i)
341
342
#define setfltvalue(obj,x) \
343
{ TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_VNUMFLT); }
344
345
#define chgfltvalue(obj,x) \
346
{ TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }
347
348
#define setivalue(obj,x) \
349
{ TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_VNUMINT); }
350
351
#define chgivalue(obj,x) \
352
{ TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }
353
354
/* }================================================================== */
355
356
357
/*
358
** {==================================================================
359
** Strings
360
** ===================================================================
361
*/
362
363
/* Variant tags for strings */
364
#define LUA_VSHRSTR makevariant(LUA_TSTRING, 0)
/* short strings */
365
#define LUA_VLNGSTR makevariant(LUA_TSTRING, 1)
/* long strings */
366
367
#define ttisstring(o) checktype((o), LUA_TSTRING)
368
#define ttisshrstring(o) checktag((o), ctb(LUA_VSHRSTR))
369
#define ttislngstring(o) checktag((o), ctb(LUA_VLNGSTR))
370
371
#define tsvalueraw(v) (gco2ts((v).gc))
372
373
#define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc))
374
375
#define setsvalue(L,obj,x) \
376
{ TValue *io = (obj); TString *x_ = (x); \
377
val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \
378
checkliveness(L,io); }
379
380
/* set a string to the stack */
381
#define setsvalue2s(L,o,s) setsvalue(L,s2v(o),s)
382
383
/* set a string to a new object */
384
#define setsvalue2n setsvalue
385
386
387
/*
388
** Header for a string value.
389
*/
390
typedef
struct
TString
{
391
CommonHeader;
392
lu_byte extra;
/* reserved words for short strings; "has hash" for longs */
393
lu_byte shrlen;
/* length for short strings */
394
unsigned
int
hash;
395
union
{
396
size_t
lnglen;
/* length for long strings */
397
struct
TString
*hnext;
/* linked list for hash table */
398
} u;
399
char
contents[1];
400
}
TString
;
401
402
403
404
/*
405
** Get the actual string (array of bytes) from a 'TString'.
406
*/
407
#define getstr(ts) ((ts)->contents)
408
409
410
/* get the actual string (array of bytes) from a Lua value */
411
#define svalue(o) getstr(tsvalue(o))
412
413
/* get string length from 'TString *s' */
414
#define tsslen(s) ((s)->tt == LUA_VSHRSTR ? (s)->shrlen : (s)->u.lnglen)
415
416
/* get string length from 'TValue *o' */
417
#define vslen(o) tsslen(tsvalue(o))
418
419
/* }================================================================== */
420
421
422
/*
423
** {==================================================================
424
** Userdata
425
** ===================================================================
426
*/
427
428
429
/*
430
** Light userdata should be a variant of userdata, but for compatibility
431
** reasons they are also different types.
432
*/
433
#define LUA_VLIGHTUSERDATA makevariant(LUA_TLIGHTUSERDATA, 0)
434
435
#define LUA_VUSERDATA makevariant(LUA_TUSERDATA, 0)
436
437
#define ttislightuserdata(o) checktag((o), LUA_VLIGHTUSERDATA)
438
#define ttisfulluserdata(o) checktag((o), ctb(LUA_VUSERDATA))
439
440
#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
441
#define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc))
442
443
#define pvalueraw(v) ((v).p)
444
445
#define setpvalue(obj,x) \
446
{ TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_VLIGHTUSERDATA); }
447
448
#define setuvalue(L,obj,x) \
449
{ TValue *io = (obj); Udata *x_ = (x); \
450
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VUSERDATA)); \
451
checkliveness(L,io); }
452
453
454
/* Ensures that addresses after this type are always fully aligned. */
455
typedef
union
UValue
{
456
TValue
uv;
457
LUAI_MAXALIGN;
/* ensures maximum alignment for udata bytes */
458
}
UValue
;
459
460
461
/*
462
** Header for userdata with user values;
463
** memory area follows the end of this structure.
464
*/
465
typedef
struct
Udata
{
466
CommonHeader;
467
unsigned
short
nuvalue;
/* number of user values */
468
size_t
len;
/* number of bytes */
469
struct
Table
*metatable;
470
GCObject
*gclist;
471
UValue
uv[1];
/* user values */
472
}
Udata
;
473
474
475
/*
476
** Header for userdata with no user values. These userdata do not need
477
** to be gray during GC, and therefore do not need a 'gclist' field.
478
** To simplify, the code always use 'Udata' for both kinds of userdata,
479
** making sure it never accesses 'gclist' on userdata with no user values.
480
** This structure here is used only to compute the correct size for
481
** this representation. (The 'bindata' field in its end ensures correct
482
** alignment for binary data following this header.)
483
*/
484
typedef
struct
Udata0
{
485
CommonHeader;
486
unsigned
short
nuvalue;
/* number of user values */
487
size_t
len;
/* number of bytes */
488
struct
Table
*metatable;
489
union
{LUAI_MAXALIGN;} bindata;
490
}
Udata0
;
491
492
493
/* compute the offset of the memory area of a userdata */
494
#define udatamemoffset(nuv) \
495
((nuv) == 0 ? offsetof(Udata0, bindata) \
496
: offsetof(Udata, uv) + (sizeof(UValue) * (nuv)))
497
498
/* get the address of the memory block inside 'Udata' */
499
#define getudatamem(u) (cast_charp(u) + udatamemoffset((u)->nuvalue))
500
501
/* compute the size of a userdata */
502
#define sizeudata(nuv,nb) (udatamemoffset(nuv) + (nb))
503
504
/* }================================================================== */
505
506
507
/*
508
** {==================================================================
509
** Prototypes
510
** ===================================================================
511
*/
512
513
#define LUA_VPROTO makevariant(LUA_TPROTO, 0)
514
515
516
/*
517
** Description of an upvalue for function prototypes
518
*/
519
typedef
struct
Upvaldesc
{
520
TString
*name;
/* upvalue name (for debug information) */
521
lu_byte instack;
/* whether it is in stack (register) */
522
lu_byte idx;
/* index of upvalue (in stack or in outer function's list) */
523
lu_byte kind;
/* kind of corresponding variable */
524
}
Upvaldesc
;
525
526
527
/*
528
** Description of a local variable for function prototypes
529
** (used for debug information)
530
*/
531
typedef
struct
LocVar
{
532
TString
*varname;
533
int
startpc;
/* first point where variable is active */
534
int
endpc;
/* first point where variable is dead */
535
}
LocVar
;
536
537
538
/*
539
** Associates the absolute line source for a given instruction ('pc').
540
** The array 'lineinfo' gives, for each instruction, the difference in
541
** lines from the previous instruction. When that difference does not
542
** fit into a byte, Lua saves the absolute line for that instruction.
543
** (Lua also saves the absolute line periodically, to speed up the
544
** computation of a line number: we can use binary search in the
545
** absolute-line array, but we must traverse the 'lineinfo' array
546
** linearly to compute a line.)
547
*/
548
typedef
struct
AbsLineInfo
{
549
int
pc;
550
int
line;
551
}
AbsLineInfo
;
552
553
/*
554
** Function Prototypes
555
*/
556
typedef
struct
Proto
{
557
CommonHeader;
558
lu_byte numparams;
/* number of fixed (named) parameters */
559
lu_byte is_vararg;
560
lu_byte maxstacksize;
/* number of registers needed by this function */
561
int
sizeupvalues;
/* size of 'upvalues' */
562
int
sizek;
/* size of 'k' */
563
int
sizecode;
564
int
sizelineinfo;
565
int
sizep;
/* size of 'p' */
566
int
sizelocvars;
567
int
sizeabslineinfo;
/* size of 'abslineinfo' */
568
int
linedefined;
/* debug information */
569
int
lastlinedefined;
/* debug information */
570
TValue
*k;
/* constants used by the function */
571
Instruction *code;
/* opcodes */
572
struct
Proto
**p;
/* functions defined inside the function */
573
Upvaldesc
*upvalues;
/* upvalue information */
574
ls_byte *lineinfo;
/* information about source lines (debug information) */
575
AbsLineInfo
*abslineinfo;
/* idem */
576
LocVar
*locvars;
/* information about local variables (debug information) */
577
TString
*source;
/* used for debug information */
578
GCObject
*gclist;
579
}
Proto
;
580
581
/* }================================================================== */
582
583
584
/*
585
** {==================================================================
586
** Functions
587
** ===================================================================
588
*/
589
590
#define LUA_VUPVAL makevariant(LUA_TUPVAL, 0)
591
592
593
/* Variant tags for functions */
594
#define LUA_VLCL makevariant(LUA_TFUNCTION, 0)
/* Lua closure */
595
#define LUA_VLCF makevariant(LUA_TFUNCTION, 1)
/* light C function */
596
#define LUA_VCCL makevariant(LUA_TFUNCTION, 2)
/* C closure */
597
598
#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
599
#define ttisLclosure(o) checktag((o), ctb(LUA_VLCL))
600
#define ttislcf(o) checktag((o), LUA_VLCF)
601
#define ttisCclosure(o) checktag((o), ctb(LUA_VCCL))
602
#define ttisclosure(o) (ttisLclosure(o) || ttisCclosure(o))
603
604
605
#define isLfunction(o) ttisLclosure(o)
606
607
#define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc))
608
#define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc))
609
#define fvalue(o) check_exp(ttislcf(o), val_(o).f)
610
#define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc))
611
612
#define fvalueraw(v) ((v).f)
613
614
#define setclLvalue(L,obj,x) \
615
{ TValue *io = (obj); LClosure *x_ = (x); \
616
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VLCL)); \
617
checkliveness(L,io); }
618
619
#define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl)
620
621
#define setfvalue(obj,x) \
622
{ TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_VLCF); }
623
624
#define setclCvalue(L,obj,x) \
625
{ TValue *io = (obj); CClosure *x_ = (x); \
626
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VCCL)); \
627
checkliveness(L,io); }
628
629
630
/*
631
** Upvalues for Lua closures
632
*/
633
typedef
struct
UpVal
{
634
CommonHeader;
635
union
{
636
TValue
*p;
/* points to stack or to its own value */
637
ptrdiff_t offset;
/* used while the stack is being reallocated */
638
} v;
639
union
{
640
struct
{
/* (when open) */
641
struct
UpVal
*next;
/* linked list */
642
struct
UpVal
**previous;
643
} open;
644
TValue
value;
/* the value (when closed) */
645
} u;
646
}
UpVal
;
647
648
649
650
#define ClosureHeader \
651
CommonHeader; lu_byte nupvalues; GCObject *gclist
652
653
typedef
struct
CClosure
{
654
ClosureHeader;
655
lua_CFunction f;
656
TValue
upvalue[1];
/* list of upvalues */
657
}
CClosure
;
658
659
660
typedef
struct
LClosure
{
661
ClosureHeader;
662
struct
Proto
*p;
663
UpVal
*upvals[1];
/* list of upvalues */
664
}
LClosure
;
665
666
667
typedef
union
Closure
{
668
CClosure
c;
669
LClosure
l;
670
}
Closure
;
671
672
673
#define getproto(o) (clLvalue(o)->p)
674
675
/* }================================================================== */
676
677
678
/*
679
** {==================================================================
680
** Tables
681
** ===================================================================
682
*/
683
684
#define LUA_VTABLE makevariant(LUA_TTABLE, 0)
685
686
#define ttistable(o) checktag((o), ctb(LUA_VTABLE))
687
688
#define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc))
689
690
#define sethvalue(L,obj,x) \
691
{ TValue *io = (obj); Table *x_ = (x); \
692
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTABLE)); \
693
checkliveness(L,io); }
694
695
#define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h)
696
697
698
/*
699
** Nodes for Hash tables: A pack of two TValue's (key-value pairs)
700
** plus a 'next' field to link colliding entries. The distribution
701
** of the key's fields ('key_tt' and 'key_val') not forming a proper
702
** 'TValue' allows for a smaller size for 'Node' both in 4-byte
703
** and 8-byte alignments.
704
*/
705
typedef
union
Node
{
706
struct
NodeKey
{
707
TValuefields;
/* fields for value */
708
lu_byte key_tt;
/* key type */
709
int
next;
/* for chaining */
710
Value
key_val;
/* key value */
711
} u;
712
TValue
i_val;
/* direct access to node's value as a proper 'TValue' */
713
}
Node
;
714
715
716
/* copy a value into a key */
717
#define setnodekey(L,node,obj) \
718
{ Node *n_=(node); const TValue *io_=(obj); \
719
n_->u.key_val = io_->value_; n_->u.key_tt = io_->tt_; \
720
checkliveness(L,io_); }
721
722
723
/* copy a value from a key */
724
#define getnodekey(L,obj,node) \
725
{ TValue *io_=(obj); const Node *n_=(node); \
726
io_->value_ = n_->u.key_val; io_->tt_ = n_->u.key_tt; \
727
checkliveness(L,io_); }
728
729
730
/*
731
** About 'alimit': if 'isrealasize(t)' is true, then 'alimit' is the
732
** real size of 'array'. Otherwise, the real size of 'array' is the
733
** smallest power of two not smaller than 'alimit' (or zero iff 'alimit'
734
** is zero); 'alimit' is then used as a hint for #t.
735
*/
736
737
#define BITRAS (1 << 7)
738
#define isrealasize(t) (!((t)->flags & BITRAS))
739
#define setrealasize(t) ((t)->flags &= cast_byte(~BITRAS))
740
#define setnorealasize(t) ((t)->flags |= BITRAS)
741
742
743
typedef
struct
Table
{
744
CommonHeader;
745
lu_byte flags;
/* 1<<p means tagmethod(p) is not present */
746
lu_byte lsizenode;
/* log2 of size of 'node' array */
747
unsigned
int
alimit;
/* "limit" of 'array' array */
748
TValue
*array;
/* array part */
749
Node
*node;
750
Node
*lastfree;
/* any free position is before this position */
751
struct
Table
*metatable;
752
GCObject
*gclist;
753
}
Table
;
754
755
756
/*
757
** Macros to manipulate keys inserted in nodes
758
*/
759
#define keytt(node) ((node)->u.key_tt)
760
#define keyval(node) ((node)->u.key_val)
761
762
#define keyisnil(node) (keytt(node) == LUA_TNIL)
763
#define keyisinteger(node) (keytt(node) == LUA_VNUMINT)
764
#define keyival(node) (keyval(node).i)
765
#define keyisshrstr(node) (keytt(node) == ctb(LUA_VSHRSTR))
766
#define keystrval(node) (gco2ts(keyval(node).gc))
767
768
#define setnilkey(node) (keytt(node) = LUA_TNIL)
769
770
#define keyiscollectable(n) (keytt(n) & BIT_ISCOLLECTABLE)
771
772
#define gckey(n) (keyval(n).gc)
773
#define gckeyN(n) (keyiscollectable(n) ? gckey(n) : NULL)
774
775
776
/*
777
** Dead keys in tables have the tag DEADKEY but keep their original
778
** gcvalue. This distinguishes them from regular keys but allows them to
779
** be found when searched in a special way. ('next' needs that to find
780
** keys removed from a table during a traversal.)
781
*/
782
#define setdeadkey(node) (keytt(node) = LUA_TDEADKEY)
783
#define keyisdead(node) (keytt(node) == LUA_TDEADKEY)
784
785
/* }================================================================== */
786
787
788
789
/*
790
** 'module' operation for hashing (size is always a power of 2)
791
*/
792
#define lmod(s,size) \
793
(check_exp((size&(size-1))==0, (cast_int((s) & ((size)-1)))))
794
795
796
#define twoto(x) (1<<(x))
797
#define sizenode(t) (twoto((t)->lsizenode))
798
799
800
/* size of buffer for 'luaO_utf8esc' function */
801
#define UTF8BUFFSZ 8
802
803
LUAI_FUNC
int
luaO_utf8esc (
char
*buff,
unsigned
long
x);
804
LUAI_FUNC
int
luaO_ceillog2 (
unsigned
int
x);
805
LUAI_FUNC
int
luaO_rawarith (
lua_State
*L,
int
op,
const
TValue
*p1,
806
const
TValue
*p2,
TValue
*res);
807
LUAI_FUNC
void
luaO_arith (
lua_State
*L,
int
op,
const
TValue
*p1,
808
const
TValue
*p2, StkId res);
809
LUAI_FUNC
size_t
luaO_str2num (
const
char
*s,
TValue
*o);
810
LUAI_FUNC
int
luaO_hexavalue (
int
c);
811
LUAI_FUNC
void
luaO_tostring (
lua_State
*L,
TValue
*obj);
812
LUAI_FUNC
const
char
*luaO_pushvfstring (
lua_State
*L,
const
char
*fmt,
813
va_list argp);
814
LUAI_FUNC
const
char
*luaO_pushfstring (
lua_State
*L,
const
char
*fmt, ...);
815
LUAI_FUNC
void
luaO_chunkid (
char
*out,
const
char
*source,
size_t
srclen);
816
817
818
#endif
819
llimits.h
lua.h
AbsLineInfo
Definition
lobject.h:548
CClosure
Definition
lobject.h:653
GCObject
Definition
lobject.h:296
LClosure
Definition
lobject.h:660
LocVar
Definition
lobject.h:531
Node::NodeKey
Definition
lobject.h:706
Proto
Definition
lobject.h:556
TString
Definition
lobject.h:390
TValue
Definition
lobject.h:71
Table
Definition
lobject.h:743
Udata0
Definition
lobject.h:484
Udata
Definition
lobject.h:465
UpVal
Definition
lobject.h:633
Upvaldesc
Definition
lobject.h:519
lua_State
Definition
lstate.h:313
Closure
Definition
lobject.h:667
Node
Definition
lobject.h:705
StackValue
Definition
lobject.h:152
StkIdRel
Definition
lobject.h:169
UValue
Definition
lobject.h:455
Value
Definition
lobject.h:53
lua
src
lobject.h
Generated by
1.18.0