2 ** $Id: lobject.h,v 1.28 1999/03/16 16:43:27 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 typedef LUA_NUM_TYPE real
;
38 #define Byte lua_Byte /* some systems have Byte as a predefined type */
39 typedef unsigned char Byte
; /* unsigned 8 bits */
42 #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
44 typedef unsigned int IntPoint
; /* unsigned with same size as a pointer (for hashing) */
49 ** WARNING: if you change the order of this enumeration,
53 LUA_T_USERDATA
= 0, /* tag default for userdata */
54 LUA_T_NUMBER
= -1, /* fixed tag for numbers */
55 LUA_T_STRING
= -2, /* fixed tag for strings */
56 LUA_T_ARRAY
= -3, /* tag default for tables (or arrays) */
57 LUA_T_PROTO
= -4, /* fixed tag for functions */
58 LUA_T_CPROTO
= -5, /* fixed tag for Cfunctions */
59 LUA_T_NIL
= -6, /* last "pre-defined" tag */
61 LUA_T_CLMARK
= -8, /* mark for closures */
62 LUA_T_PMARK
= -9, /* mark for Lua prototypes */
63 LUA_T_CMARK
= -10, /* mark for C prototypes */
71 lua_CFunction f
; /* LUA_T_CPROTO, LUA_T_CMARK */
72 real n
; /* LUA_T_NUMBER */
73 struct TaggedString
*ts
; /* LUA_T_STRING, LUA_T_USERDATA */
74 struct TProtoFunc
*tf
; /* LUA_T_PROTO, LUA_T_PMARK */
75 struct Closure
*cl
; /* LUA_T_CLOSURE, LUA_T_CLMARK */
76 struct Hash
*a
; /* LUA_T_ARRAY */
77 int i
; /* LUA_T_LINE */
81 typedef struct TObject
{
89 ** generic header for garbage collector lists
91 typedef struct GCnode
{
98 ** String headers for string table
101 typedef struct TaggedString
{
104 int constindex
; /* hint to reuse constants (= -1 if this is a userdata) */
108 long len
; /* if this is a string, here is its length */
112 void *v
; /* if this is a userdata, here is its value */
115 char str
[1]; /* \0 byte already reserved */
122 ** Function Prototypes
124 typedef struct TProtoFunc
{
126 struct TObject
*consts
;
128 Byte
*code
; /* ends with opcode ENDCODE */
130 TaggedString
*source
;
131 struct LocVar
*locvars
; /* ends with line = -1 */
134 typedef struct LocVar
{
135 TaggedString
*varname
; /* NULL signals end of scope */
143 /* Macros to access structure members */
144 #define ttype(o) ((o)->ttype)
145 #define nvalue(o) ((o)->value.n)
146 #define svalue(o) ((o)->value.ts->str)
147 #define tsvalue(o) ((o)->value.ts)
148 #define clvalue(o) ((o)->value.cl)
149 #define avalue(o) ((o)->value.a)
150 #define fvalue(o) ((o)->value.f)
151 #define tfvalue(o) ((o)->value.tf)
153 #define protovalue(o) ((o)->value.cl->consts)
159 typedef struct Closure
{
161 int nelems
; /* not included the first one (always the prototype) */
162 TObject consts
[1]; /* at least one for prototype */
167 typedef struct node
{
172 typedef struct Hash
{
181 extern char *luaO_typenames
[];
183 #define luaO_typename(o) luaO_typenames[-ttype(o)]
186 extern TObject luaO_nilobject
;
188 #define luaO_equalObj(t1,t2) ((ttype(t1) != ttype(t2)) ? 0 \
189 : luaO_equalval(t1,t2))
190 int luaO_equalval (TObject
*t1
, TObject
*t2
);
191 int luaO_redimension (int oldsize
);
192 void luaO_insertlist (GCnode
*root
, GCnode
*node
);
193 double luaO_str2d (char *s
);
196 void luaO_memup (void *dest
, void *src
, int size
);
197 void luaO_memdown (void *dest
, void *src
, int size
);
200 #define luaO_memup(d,s,n) memmove(d,s,n)
201 #define luaO_memdown(d,s,n) memmove(d,s,n)