-
Notifications
You must be signed in to change notification settings - Fork 32
/
lobject.h
156 lines (108 loc) · 4.26 KB
/
lobject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Value vs. GCObject vs. GCUnion
---------------------
Values (or TValue, more strictly speaking) are what is associated with Lua variables.
TValues reside in stack. Values represent UpVals. TValues act as table fields.
GCObjects reside only in the heap. They are referred by Values.
GCUnion represents all subclasses of GCObject.
StkId --> TValue --> lua_TValue --> (contains) TValuefields
TValuefields
-----------------
Value is untagged (having no type information). TValue means "tagged" value, value augmented
with type tag (tt_).
-----------------
value (Value) ---> (union) gc (GCObject)
tt_ (int) p (void)
b (int)
f (lua_CFunction)
n (ua_Number)
setnilvalue(obj)
==================
Assign *tt_* field as LUA_TNIL
GCUnion
-----------------
"gclist" is the next node of the gray list if the object resides in one such list.
-------------------------------------------------
GCObject* next |
lu_byte tt | Common header
lu_byte marked |
-------------------------------------------------
lu_byte nupvalues | Closure header
GCObject* gclist |
-------------------------------------------------
TString
-------------------------------------------------
GCObject* next |
lu_byte tt | Common header
lu_byte marked |
-------------------------------------------------
lu_byte extra |
unsigned int hash |
size_t len |
TString* next |
-------------------------------------------------
UpVal
-----------------
UpVal is no longer a GCObject like it was in 5.2.
UpVal is no longer linked to g->uvhead, but only linked to L->openupval.
-------------------------------------------------------------------------------------
TValue* v | linked to either in-stack value or to "value"
lu_mem refcount |
-------------------------------------------------------------------------------------
TValue value | UpVal* next | linked to "L->openupval". In 5.2 it was to g->uvhead
| int touched |
-------------------------------------------------------------------------------------
Table
-----------------
-------------------------------------------------
GCObject* next |
lu_byte tt | Common header
lu_byte marked |
-------------------------------------------------
lu_byte flags | Presence of meta-method. "1" means absent. All "1" at initialized.
lu_byte lsizenode | Log(sizenode), so there is no "sizenode" field
... |
Node* node | Hashed key-value
... |
UData
-----------------
-------------------------------------------------
GCObject* next |
lu_byte tt | Common header
lu_byte marked |
-------------------------------------------------
lu_byte ttuv_ | New in 5.3
Table* metatable |
size_t len |
Value user_ | New in 5.3. Holding any Lua type. In 5.2, it was "env" which holds table type only.
| Note: "env" in 5.2 does not really mean env. Just an ordinary table.
-------------------------------------------------
... (real data)
-------------------------------------------------
Proto
-----------------
-------------------------------------------------
GCObject* next |
lu_byte tt | Common header
lu_byte marked |
-------------------------------------------------
... |
--------------------------------------------------------------------------------------------------
LocVar* locvars | TString* varname | debug and parsing information for local-var,
| int startpc | used for var-seach in parsing. indexed by
| int endpc | "Dyndata::actvar.arr".
--------------------------------------------------------------------------------------------------
... |
int sizecode | size of "code"
int sizelineinfo | size of "lineinfo"
... |
lu_byte is_vararg | it has mere two possible values now, 0 or 1.
lu_byte upvalues | for the _description_ of upvalues. For example, if an upval shall be
| on the stack (locals of enclosing function).
Closure
-----------------
upvals: Reference to real upvals. Its initialization is made according to
Proto.upvalues specification.
setgcovalue(L,obj,x)
==================
Set TValue "obj" pointing to collectable object "x", including make "obj" and "x"
marked as the same type ("tt_" field of the former and "tt" field of the latter).