aboutsummaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-09-16 16:25:59 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-09-16 16:25:59 -0300
commit2f1fa3d427b783490c2f0efb7dfe0090e291692f (patch)
tree67ff989c1209544f87ccf9eaee42c0a81411f69e /lobject.h
parent189d64409b5f7e09fb7650e7217d55277b1fccba (diff)
downloadlua-2f1fa3d427b783490c2f0efb7dfe0090e291692f.tar.gz
lua-2f1fa3d427b783490c2f0efb7dfe0090e291692f.tar.bz2
lua-2f1fa3d427b783490c2f0efb7dfe0090e291692f.zip
Type definitions for Lua objects
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h171
1 files changed, 171 insertions, 0 deletions
diff --git a/lobject.h b/lobject.h
new file mode 100644
index 00000000..710d4a6a
--- /dev/null
+++ b/lobject.h
@@ -0,0 +1,171 @@
1/*
2** $Id: $
3** Type definitions for Lua objects
4** See Copyright Notice in lua.h
5*/
6
7#ifndef lobject_h
8#define lobject_h
9
10
11#include "lua.h"
12
13
14#include <limits.h>
15
16#ifndef real
17#define real float
18#endif
19
20#define Byte lua_Byte /* some systems have Byte as a predefined type */
21typedef unsigned char Byte; /* unsigned 8 bits */
22
23#define Word lua_Word /* some systems have Word as a predefined type */
24typedef unsigned short Word; /* unsigned 16 bits */
25
26#define MAX_WORD (USHRT_MAX-2) /* maximum value of a word (-2 for safety) */
27#define MAX_INT (INT_MAX-2) /* maximum value of a int (-2 for safety) */
28
29typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hashing) */
30
31
32
33
34/*
35** String headers for string table
36*/
37
38#define NOT_USED 0xFFFE
39
40typedef struct TaggedString {
41 int tag; /* if != LUA_T_STRING, this is a userdata */
42 union {
43 unsigned long hash;
44 struct TaggedString *next;
45 } uu;
46 union {
47 struct {
48 Word varindex; /* != NOT_USED if this is a symbol */
49 Word constindex; /* hint to reuse constant indexes */
50 } s;
51 void *v; /* if this is a userdata, here is its value */
52 } u;
53 int marked; /* for garbage collection; never collect (nor change) if > 1 */
54 char str[1]; /* \0 byte already reserved */
55} TaggedString;
56
57
58
59/*
60** generic header for garbage collector lists
61*/
62typedef struct GCnode {
63 struct GCnode *next;
64 int marked;
65} GCnode;
66
67
68/*
69** Function Prototypes
70*/
71typedef struct TProtoFunc {
72 GCnode head;
73 Byte *code; /* ends with opcode ENDCODE */
74 int lineDefined;
75 TaggedString *fileName;
76 struct TObject *consts;
77 int nconsts;
78 struct LocVar *locvars; /* ends with line = -1 */
79 int nupvalues;
80} TProtoFunc;
81
82typedef struct LocVar {
83 TaggedString *varname; /* NULL signals end of scope */
84 int line;
85} LocVar;
86
87
88
89
90/*
91** Lua TYPES
92** WARNING: if you change the order of this enumeration,
93** grep "ORDER LUA_T"
94*/
95typedef enum {
96 LUA_T_NIL = -10,
97 LUA_T_NUMBER = -9,
98 LUA_T_STRING = -8,
99 LUA_T_ARRAY = -7, /* array==table */
100 LUA_T_PROTO = -6,
101 LUA_T_FUNCTION = -5,
102 LUA_T_CFUNCTION= -4,
103 LUA_T_MARK = -3,
104 LUA_T_CMARK = -2,
105 LUA_T_LINE = -1,
106 LUA_T_USERDATA = 0
107} lua_Type;
108
109#define NUM_TYPES 11
110
111
112typedef union {
113 lua_CFunction f;
114 real n;
115 TaggedString *ts;
116 TProtoFunc *tf;
117 struct Closure *cl;
118 struct Hash *a;
119 int i;
120} Value;
121
122typedef struct TObject {
123 lua_Type ttype;
124 Value value;
125} TObject;
126
127
128/* Macros to access structure members */
129#define ttype(o) ((o)->ttype)
130#define nvalue(o) ((o)->value.n)
131#define svalue(o) ((o)->value.ts->str)
132#define tsvalue(o) ((o)->value.ts)
133#define clvalue(o) ((o)->value.cl)
134#define avalue(o) ((o)->value.a)
135#define fvalue(o) ((o)->value.f)
136#define tfvalue(o) ((o)->value.tf)
137
138
139/*
140** Closures
141*/
142typedef struct Closure {
143 GCnode head;
144 TObject consts[1]; /* at least one for prototype */
145} Closure;
146
147
148
149typedef struct node {
150 TObject ref;
151 TObject val;
152} Node;
153
154typedef struct Hash {
155 GCnode head;
156 Node *node;
157 int nhash;
158 int nuse;
159 int htag;
160} Hash;
161
162
163extern long luaO_nentities;
164extern char *luaO_typenames[];
165
166int luaO_equalObj (TObject *t1, TObject *t2);
167int luaO_redimension (int oldsize);
168int luaO_findstring (char *name, char *list[]);
169
170
171#endif