A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/*
2** $Id$
3** Type definitions for Lua objects
4** See Copyright Notice in lua.h
5*/
6
7
8#ifndef lobject_h
9#define lobject_h
10
11
12#include <stdarg.h>
13
14
15#include "llimits.h"
16#include "lua.h"
17
18
19/* tags for values visible from Lua */
20#define LAST_TAG LUA_TTHREAD
21
22#define NUM_TAGS (LAST_TAG+1)
23
24
25/*
26** Extra tags for non-values
27*/
28#define LUA_TPROTO (LAST_TAG+1)
29#define LUA_TUPVAL (LAST_TAG+2)
30#define LUA_TDEADKEY (LAST_TAG+3)
31
32
33/*
34** Union of all collectable objects
35*/
36typedef union GCObject GCObject;
37
38
39/*
40** Common Header for all collectable objects (in macro form, to be
41** included in other objects)
42*/
43#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked
44
45
46/*
47** Common header in struct form
48*/
49typedef struct GCheader {
50 CommonHeader;
51} GCheader;
52
53
54
55
56/*
57** Union of all Lua values
58*/
59typedef union {
60 GCObject *gc;
61 void *p;
62 lua_Number n;
63 int b;
64} Value;
65
66
67/*
68** Tagged Values
69*/
70
71#define TValuefields Value value; int tt
72
73typedef struct lua_TValue {
74 TValuefields;
75} TValue;
76
77
78/* Macros to test type */
79#define ttisnil(o) (ttype(o) == LUA_TNIL)
80#define ttisnumber(o) (ttype(o) == LUA_TNUMBER)
81#define ttisstring(o) (ttype(o) == LUA_TSTRING)
82#define ttistable(o) (ttype(o) == LUA_TTABLE)
83#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION)
84#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN)
85#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA)
86#define ttisthread(o) (ttype(o) == LUA_TTHREAD)
87#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA)
88
89/* Macros to access values */
90#define ttype(o) ((o)->tt)
91#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc)
92#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p)
93#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n)
94#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts)
95#define tsvalue(o) (&rawtsvalue(o)->tsv)
96#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u)
97#define uvalue(o) (&rawuvalue(o)->uv)
98#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl)
99#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h)
100#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b)
101#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th)
102
103#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
104
105/*
106** for internal debug only
107*/
108#define checkconsistency(obj) \
109 lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
110
111#define checkliveness(g,obj) \
112 lua_assert(!iscollectable(obj) || \
113 ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc)))
114
115
116/* Macros to set values */
117#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
118
119#define setnvalue(obj,x) \
120 { lua_Number i_x = (x); TValue *i_o=(obj); i_o->value.n=i_x; i_o->tt=LUA_TNUMBER; }
121
122#define setpvalue(obj,x) \
123 { void *i_x = (x); TValue *i_o=(obj); i_o->value.p=i_x; i_o->tt=LUA_TLIGHTUSERDATA; }
124
125#define setbvalue(obj,x) \
126 { int i_x = (x); TValue *i_o=(obj); i_o->value.b=i_x; i_o->tt=LUA_TBOOLEAN; }
127
128#define setsvalue(L,obj,x) \
129 { GCObject *i_x = cast(GCObject *, (x)); \
130 TValue *i_o=(obj); \
131 i_o->value.gc=i_x; i_o->tt=LUA_TSTRING; \
132 checkliveness(G(L),i_o); }
133
134#define setuvalue(L,obj,x) \
135 { GCObject *i_x = cast(GCObject *, (x)); \
136 TValue *i_o=(obj); \
137 i_o->value.gc=i_x; i_o->tt=LUA_TUSERDATA; \
138 checkliveness(G(L),i_o); }
139
140#define setthvalue(L,obj,x) \
141 { GCObject *i_x = cast(GCObject *, (x)); \
142 TValue *i_o=(obj); \
143 i_o->value.gc=i_x; i_o->tt=LUA_TTHREAD; \
144 checkliveness(G(L),i_o); }
145
146#define setclvalue(L,obj,x) \
147 { GCObject *i_x = cast(GCObject *, (x)); \
148 TValue *i_o=(obj); \
149 i_o->value.gc=i_x; i_o->tt=LUA_TFUNCTION; \
150 checkliveness(G(L),i_o); }
151
152#define sethvalue(L,obj,x) \
153 { GCObject *i_x = cast(GCObject *, (x)); \
154 TValue *i_o=(obj); \
155 i_o->value.gc=i_x; i_o->tt=LUA_TTABLE; \
156 checkliveness(G(L),i_o); }
157
158#define setptvalue(L,obj,x) \
159 { GCObject *i_x = cast(GCObject *, (x)); \
160 TValue *i_o=(obj); \
161 i_o->value.gc=i_x; i_o->tt=LUA_TPROTO; \
162 checkliveness(G(L),i_o); }
163
164
165
166
167#define setobj(L,obj1,obj2) \
168 { const TValue *o2=(obj2); TValue *o1=(obj1); \
169 o1->value = o2->value; o1->tt=o2->tt; \
170 checkliveness(G(L),o1); }
171
172
173/*
174** different types of sets, according to destination
175*/
176
177/* from stack to (same) stack */
178#define setobjs2s setobj
179/* to stack (not from same stack) */
180#define setobj2s setobj
181#define setsvalue2s setsvalue
182#define sethvalue2s sethvalue
183#define setptvalue2s setptvalue
184/* from table to same table */
185#define setobjt2t setobj
186/* to table */
187#define setobj2t setobj
188/* to new object */
189#define setobj2n setobj
190#define setsvalue2n setsvalue
191
192#define setttype(obj, tt) (ttype(obj) = (tt))
193
194
195#define iscollectable(o) (ttype(o) >= LUA_TSTRING)
196
197
198
199typedef TValue *StkId; /* index to stack elements */
200
201
202/*
203** String headers for string table
204*/
205typedef union TString {
206 L_Umaxalign dummy; /* ensures maximum alignment for strings */
207 struct {
208 CommonHeader;
209 lu_byte reserved;
210 lu_byte type;
211 unsigned int hash;
212 size_t len;
213 } tsv;
214} TString;
215
216
217#define getstr(ts) (luaO_getstring(ts)) /* ROCKLUA ADDED */
218#define svalue(o) getstr(rawtsvalue(o))
219
220
221
222typedef union Udata {
223 L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
224 struct {
225 CommonHeader;
226 struct Table *metatable;
227 struct Table *env;
228 size_t len;
229 } uv;
230} Udata;
231
232
233
234
235/*
236** Function Prototypes
237*/
238typedef struct Proto {
239 CommonHeader;
240 TValue *k; /* constants used by the function */
241 Instruction *code;
242 struct Proto **p; /* functions defined inside the function */
243#ifdef LUA_OPTIMIZE_DEBUG
244 unsigned char *packedlineinfo;
245#else
246 int *lineinfo; /* map from opcodes to source lines */
247#endif
248 struct LocVar *locvars; /* information about local variables */
249 TString **upvalues; /* upvalue names */
250 TString *source;
251 int sizeupvalues;
252 int sizek; /* size of `k' */
253 int sizecode;
254 int sizelineinfo;
255 int sizep; /* size of `p' */
256 int sizelocvars;
257 int linedefined;
258 int lastlinedefined;
259 GCObject *gclist;
260 lu_byte nups; /* number of upvalues */
261 lu_byte numparams;
262 lu_byte is_vararg;
263 lu_byte maxstacksize;
264} Proto;
265
266
267/* masks for new-style vararg */
268#define VARARG_HASARG 1
269#define VARARG_ISVARARG 2
270#define VARARG_NEEDSARG 4
271
272
273typedef struct LocVar {
274 TString *varname;
275 int startpc; /* first point where variable is active */
276 int endpc; /* first point where variable is dead */
277} LocVar;
278
279
280
281/*
282** Upvalues
283*/
284
285typedef struct UpVal {
286 CommonHeader;
287 TValue *v; /* points to stack or to its own value */
288 union {
289 TValue value; /* the value (when closed) */
290 struct { /* double linked list (when open) */
291 struct UpVal *prev;
292 struct UpVal *next;
293 } l;
294 } u;
295} UpVal;
296
297
298/*
299** Closures
300*/
301
302#define ClosureHeader \
303 CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \
304 struct Table *env
305
306typedef struct CClosure {
307 ClosureHeader;
308 lua_CFunction f;
309 TValue upvalue[1];
310} CClosure;
311
312
313typedef struct LClosure {
314 ClosureHeader;
315 struct Proto *p;
316 UpVal *upvals[1];
317} LClosure;
318
319
320typedef union Closure {
321 CClosure c;
322 LClosure l;
323} Closure;
324
325
326#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC)
327#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC)
328
329
330/*
331** Tables
332*/
333
334typedef union TKey {
335 struct {
336 TValuefields;
337 struct Node *next; /* for chaining */
338 } nk;
339 TValue tvk;
340} TKey;
341
342
343typedef struct Node {
344 TValue i_val;
345 TKey i_key;
346} Node;
347
348
349typedef struct Table {
350 CommonHeader;
351 lu_byte flags; /* 1<<p means tagmethod(p) is not present */
352 lu_byte lsizenode; /* log2 of size of `node' array */
353 struct Table *metatable;
354 TValue *array; /* array part */
355 Node *node;
356 Node *lastfree; /* any free position is before this position */
357 GCObject *gclist;
358 int sizearray; /* size of `array' array */
359} Table;
360
361
362
363/*
364** `module' operation for hashing (size is always a power of 2)
365*/
366#define lmod(s,size) \
367 (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))
368
369
370#define twoto(x) (1<<(x))
371#define sizenode(t) (twoto((t)->lsizenode))
372
373
374#define luaO_nilobject (&luaO_nilobject_)
375
376LUAI_DATA const TValue luaO_nilobject_;
377
378#define ceillog2(x) (luaO_log2((x)-1) + 1)
379
380LUAI_FUNC int luaO_log2 (unsigned int x);
381LUAI_FUNC int luaO_int2fb (unsigned int x);
382LUAI_FUNC int luaO_fb2int (int x);
383LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2);
384LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result);
385LUAI_FUNC const char *luaO_getstring(const TString * ts); /* ROCKLUA ADDED */
386LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
387 va_list argp);
388LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
389LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
390
391
392#endif
393