2
** $Id: lobject.h,v 1.1 2003/02/09 21:30:32 dheck Exp $
3
** Type definitions for Lua objects
4
** See Copyright Notice in lua.h
18
#define LUA_INTERNALERROR(s) assert(((void)s,0))
19
#define LUA_ASSERT(c,s) assert(((void)s,(c)))
21
#define LUA_INTERNALERROR(s) /* empty */
22
#define LUA_ASSERT(c,s) /* empty */
27
/* to avoid warnings, and make sure value is really unused */
28
#define UNUSED(x) (x=0, (void)(x))
30
#define UNUSED(x) ((void)(x)) /* to avoid warnings */
34
/* mark for closures active in the stack */
38
/* tags for values visible from Lua == first user-created tag */
42
/* check whether `t' is a mark */
43
#define is_T_MARK(t) ((t) == LUA_TMARK)
47
struct TString *ts; /* LUA_TSTRING, LUA_TUSERDATA */
48
struct Closure *cl; /* LUA_TFUNCTION */
49
struct Hash *a; /* LUA_TTABLE */
50
struct CallInfo *i; /* LUA_TLMARK */
51
Number n; /* LUA_TNUMBER */
55
/* Macros to access values */
56
#define ttype(o) ((o)->ttype)
57
#define nvalue(o) ((o)->value.n)
58
#define tsvalue(o) ((o)->value.ts)
59
#define clvalue(o) ((o)->value.cl)
60
#define hvalue(o) ((o)->value.a)
61
#define infovalue(o) ((o)->value.i)
62
#define svalue(o) (tsvalue(o)->str)
65
typedef struct lua_TObject {
72
** String headers for string table
76
** most `malloc' libraries allocate memory in blocks of 8 bytes. TSPACK
77
** tries to make sizeof(TString) a multiple of this granularity, to reduce
80
#define TSPACK ((int)sizeof(int))
82
typedef struct TString {
84
struct { /* for strings */
86
int constindex; /* hint to reuse constants */
88
struct { /* for userdata */
94
struct TString *nexthash; /* chain for hash table */
96
char str[TSPACK]; /* variable length string!! must be the last field! */
101
** Function Prototypes
103
typedef struct Proto {
104
Number *knum; /* Number numbers used by the function */
105
int nknum; /* size of `knum' */
106
struct TString **kstr; /* strings used by the function */
107
int nkstr; /* size of `kstr' */
108
struct Proto **kproto; /* functions defined inside the function */
109
int nkproto; /* size of `kproto' */
111
int ncode; /* size of `code'; when 0 means an incomplete `Proto' */
117
/* debug information */
118
int *lineinfo; /* map from opcodes to source lines */
119
int nlineinfo; /* size of `lineinfo' */
121
struct LocVar *locvars; /* information about local variables */
127
typedef struct LocVar {
129
int startpc; /* first point where variable is active */
130
int endpc; /* first point where variable is dead */
137
typedef struct Closure {
139
lua_CFunction c; /* C functions */
140
struct Proto *l; /* Lua functions */
142
struct Closure *next;
143
struct Closure *mark; /* marked closures (point to itself when not marked) */
144
short isC; /* 0 for Lua functions, 1 for C functions */
150
#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->isC)
153
typedef struct Node {
156
struct Node *next; /* for chaining */
159
typedef struct Hash {
163
Node *firstfree; /* this position is free; all positions after it are full */
165
struct Hash *mark; /* marked tables (point to itself when not marked) */
169
/* unmarked tables and closures are represented by pointing `mark' to
172
#define ismarked(x) ((x)->mark != (x))
176
** informations about a call (for debugging)
178
typedef struct CallInfo {
179
struct Closure *func; /* function being called */
180
const Instruction **pc; /* current pc of called function */
181
int lastpc; /* last pc traced */
182
int line; /* current line */
183
int refi; /* current index in `lineinfo' */
187
extern const TObject luaO_nilobject;
188
extern const char *const luaO_typenames[];
191
#define luaO_typename(o) (luaO_typenames[ttype(o)])
194
lint32 luaO_power2 (lint32 n);
195
char *luaO_openspace (lua_State *L, size_t n);
197
int luaO_equalObj (const TObject *t1, const TObject *t2);
198
int luaO_str2d (const char *s, Number *result);
200
void luaO_verror (lua_State *L, const char *fmt, ...);
201
void luaO_chunkid (char *out, const char *source, int len);