2 ** $Id: lobject.h,v 1.21 1998/06/18 16:57:03 roberto Exp $
3 ** Type definitions for Lua objects
4 ** See Copyright Notice in lua.h
18 #define LUA_INTERNALERROR(s) \
19 luaL_verror("INTERNAL ERROR - %s [%s:%d]",(s),__FILE__,__LINE__)
20 #define LUA_ASSERT(c,s) { if (!(c)) LUA_INTERNALERROR(s); }
22 #define LUA_INTERNALERROR(s) /* empty */
23 #define LUA_ASSERT(c,s) /* empty */
28 ** "real" is the type "number" of Lua
29 ** GREP LUA_NUMBER to change that
32 #define LUA_NUM_TYPE double
36 ** format to convert number to strings
38 #define NUMBER_FMT "%g"
40 typedef LUA_NUM_TYPE real
;
42 #define Byte lua_Byte /* some systems have Byte as a predefined type */
43 typedef unsigned char Byte
; /* unsigned 8 bits */
46 #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
48 /* maximum value of a word of 2 bytes (-2 for safety); must fit in an "int" */
50 #define MAX_WORD MAX_INT
52 #define MAX_WORD 65534
55 typedef unsigned int IntPoint
; /* unsigned with same size as a pointer (for hashing) */
60 ** WARNING: if you change the order of this enumeration,
64 LUA_T_USERDATA
= 0, /* tag default for userdata */
65 LUA_T_NUMBER
= -1, /* fixed tag for numbers */
66 LUA_T_STRING
= -2, /* fixed tag for strings */
67 LUA_T_ARRAY
= -3, /* tag default for tables (or arrays) */
68 LUA_T_PROTO
= -4, /* fixed tag for functions */
69 LUA_T_CPROTO
= -5, /* fixed tag for Cfunctions */
70 LUA_T_NIL
= -6, /* last "pre-defined" tag */
72 LUA_T_CLMARK
= -8, /* mark for closures */
73 LUA_T_PMARK
= -9, /* mark for Lua prototypes */
74 LUA_T_CMARK
= -10, /* mark for C prototypes */
83 lua_CFunction f
; /* LUA_T_CPROTO, LUA_T_CMARK */
84 real n
; /* LUA_T_NUMBER */
85 struct TaggedString
*ts
; /* LUA_T_STRING, LUA_T_USERDATA */
86 struct TProtoFunc
*tf
; /* LUA_T_PROTO, LUA_T_PMARK */
87 struct Closure
*cl
; /* LUA_T_CLOSURE, LUA_T_CLMARK */
88 struct Hash
*a
; /* LUA_T_ARRAY */
89 int i
; /* LUA_T_LINE */
93 typedef struct TObject
{
101 ** generic header for garbage collector lists
103 typedef struct GCnode
{
110 ** String headers for string table
113 typedef struct TaggedString
{
116 int constindex
; /* hint to reuse constants (= -1 if this is a userdata) */
120 long len
; /* if this is a string, here is its length */
124 void *v
; /* if this is a userdata, here is its value */
127 char str
[1]; /* \0 byte already reserved */
134 ** Function Prototypes
136 typedef struct TProtoFunc
{
138 struct TObject
*consts
;
140 Byte
*code
; /* ends with opcode ENDCODE */
142 TaggedString
*fileName
;
143 struct LocVar
*locvars
; /* ends with line = -1 */
146 typedef struct LocVar
{
147 TaggedString
*varname
; /* NULL signals end of scope */
155 /* Macros to access structure members */
156 #define ttype(o) ((o)->ttype)
157 #define nvalue(o) ((o)->value.n)
158 #define svalue(o) ((o)->value.ts->str)
159 #define tsvalue(o) ((o)->value.ts)
160 #define clvalue(o) ((o)->value.cl)
161 #define avalue(o) ((o)->value.a)
162 #define fvalue(o) ((o)->value.f)
163 #define tfvalue(o) ((o)->value.tf)
165 #define protovalue(o) ((o)->value.cl->consts)
171 typedef struct Closure
{
173 int nelems
; /* not included the first one (always the prototype) */
174 TObject consts
[1]; /* at least one for prototype */
179 typedef struct node
{
184 typedef struct Hash
{
193 extern char *luaO_typenames
[];
195 extern TObject luaO_nilobject
;
197 int luaO_equalObj (TObject
*t1
, TObject
*t2
);
198 int luaO_redimension (int oldsize
);
199 void luaO_insertlist (GCnode
*root
, GCnode
*node
);
202 void luaO_memup (void *dest
, void *src
, int size
);
203 void luaO_memdown (void *dest
, void *src
, int size
);
206 #define luaO_memup(d,s,n) memmove(d,s,n)
207 #define luaO_memdown(d,s,n) memmove(d,s,n)