1997-09-16 23:25:59 +04:00
|
|
|
/*
|
1999-12-27 20:33:22 +03:00
|
|
|
** $Id: lobject.h,v 1.41 1999/12/23 18:19:57 roberto Exp roberto $
|
1997-09-16 23:25:59 +04:00
|
|
|
** Type definitions for Lua objects
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lobject_h
|
|
|
|
#define lobject_h
|
|
|
|
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
1997-12-26 21:38:16 +03:00
|
|
|
#include "lua.h"
|
|
|
|
|
1997-12-23 22:24:19 +03:00
|
|
|
|
1998-03-10 00:49:52 +03:00
|
|
|
#ifdef DEBUG
|
1999-10-11 20:13:42 +04:00
|
|
|
#ifdef NDEBUG
|
|
|
|
#undef NDEBUG
|
|
|
|
#endif
|
|
|
|
#include <assert.h>
|
1999-11-22 16:12:07 +03:00
|
|
|
#define LUA_INTERNALERROR(L,s) assert(0)
|
|
|
|
#define LUA_ASSERT(L,c,s) assert(c)
|
1998-03-10 00:49:52 +03:00
|
|
|
#else
|
1999-11-22 16:12:07 +03:00
|
|
|
#define LUA_INTERNALERROR(L,s) /* empty */
|
|
|
|
#define LUA_ASSERT(L,c,s) /* empty */
|
1998-03-10 00:49:52 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-12-02 19:24:45 +03:00
|
|
|
#define UNUSED(x) (void)x /* to avoid warnings */
|
|
|
|
|
1997-12-23 22:24:19 +03:00
|
|
|
/*
|
|
|
|
** "real" is the type "number" of Lua
|
|
|
|
** GREP LUA_NUMBER to change that
|
|
|
|
*/
|
1998-05-19 02:26:03 +04:00
|
|
|
#ifndef LUA_NUM_TYPE
|
|
|
|
#define LUA_NUM_TYPE double
|
1997-09-16 23:25:59 +04:00
|
|
|
#endif
|
|
|
|
|
1998-06-11 22:21:37 +04:00
|
|
|
|
1998-05-19 02:26:03 +04:00
|
|
|
typedef LUA_NUM_TYPE real;
|
1997-12-23 22:24:19 +03:00
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
#define Byte lua_Byte /* some systems have Byte as a predefined type */
|
|
|
|
typedef unsigned char Byte; /* unsigned 8 bits */
|
|
|
|
|
1998-01-19 22:49:22 +03:00
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
|
1998-01-19 22:49:22 +03:00
|
|
|
|
1999-11-10 18:39:35 +03:00
|
|
|
|
1999-12-27 20:33:22 +03:00
|
|
|
/* conversion of pointer to int (for hashing only) */
|
1999-11-26 21:59:20 +03:00
|
|
|
/* (the shift removes bits that are usually 0 because of alignment) */
|
|
|
|
#define IntPoint(L, p) (((unsigned int)(p)) >> 3)
|
1999-11-10 18:39:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** number of `blocks' for garbage collection: each reference to other
|
|
|
|
** objects count 1, and each 32 bytes of `raw' memory count 1; we add
|
|
|
|
** 2 to the total as a minimum (and also to count the overhead of malloc)
|
|
|
|
*/
|
1999-11-22 16:12:07 +03:00
|
|
|
#define numblocks(L, o,b) ((o)+(b)/32+2)
|
1997-09-16 23:25:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-09-26 19:02:26 +04:00
|
|
|
** Lua TYPES
|
|
|
|
** WARNING: if you change the order of this enumeration,
|
|
|
|
** grep "ORDER LUA_T"
|
1997-09-16 23:25:59 +04:00
|
|
|
*/
|
1997-09-26 19:02:26 +04:00
|
|
|
typedef enum {
|
1999-12-27 20:33:22 +03:00
|
|
|
LUA_T_USERDATA = 0, /* default tag for userdata */
|
1997-10-17 00:07:40 +04:00
|
|
|
LUA_T_NUMBER = -1, /* fixed tag for numbers */
|
|
|
|
LUA_T_STRING = -2, /* fixed tag for strings */
|
1999-12-27 20:33:22 +03:00
|
|
|
LUA_T_ARRAY = -3, /* default tag for tables (or arrays) */
|
1999-12-23 21:19:57 +03:00
|
|
|
LUA_T_LPROTO = -4, /* fixed tag for Lua functions */
|
|
|
|
LUA_T_CPROTO = -5, /* fixed tag for C functions */
|
1997-10-17 00:07:40 +04:00
|
|
|
LUA_T_NIL = -6, /* last "pre-defined" tag */
|
1999-12-23 21:19:57 +03:00
|
|
|
LUA_T_LCLOSURE = -7, /* Lua closure */
|
|
|
|
LUA_T_CCLOSURE = -8, /* C closure */
|
|
|
|
LUA_T_LCLMARK = -9 ,/* mark for Lua closures */
|
|
|
|
LUA_T_CCLMARK = -10,/* mark for C closures */
|
|
|
|
LUA_T_LMARK = -11, /* mark for Lua prototypes */
|
|
|
|
LUA_T_CMARK = -12, /* mark for C prototypes */
|
|
|
|
LUA_T_LINE = -13
|
1997-09-26 19:02:26 +04:00
|
|
|
} lua_Type;
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1997-10-17 00:07:40 +04:00
|
|
|
#define NUM_TAGS 7
|
1997-09-26 19:02:26 +04:00
|
|
|
|
1999-12-23 21:19:57 +03:00
|
|
|
/*
|
1999-12-27 20:33:22 +03:00
|
|
|
** chech whether `t' is a mark; ttypes are negative numbers, so the
|
1999-12-23 21:19:57 +03:00
|
|
|
** comparisons look reversed. (ORDER LUA_T)
|
|
|
|
*/
|
|
|
|
#define is_T_MARK(t) (LUA_T_CMARK <= (t) && (t) <= LUA_T_LCLMARK)
|
|
|
|
|
1997-09-26 19:02:26 +04:00
|
|
|
|
|
|
|
typedef union {
|
1997-12-15 19:17:20 +03:00
|
|
|
lua_CFunction f; /* LUA_T_CPROTO, LUA_T_CMARK */
|
1997-09-26 19:02:26 +04:00
|
|
|
real n; /* LUA_T_NUMBER */
|
|
|
|
struct TaggedString *ts; /* LUA_T_STRING, LUA_T_USERDATA */
|
1999-12-23 21:19:57 +03:00
|
|
|
struct TProtoFunc *tf; /* LUA_T_LPROTO, LUA_T_LMARK */
|
|
|
|
struct Closure *cl; /* LUA_T_[CL]CLOSURE, LUA_T_[CL]CLMARK */
|
1997-09-26 19:02:26 +04:00
|
|
|
struct Hash *a; /* LUA_T_ARRAY */
|
|
|
|
int i; /* LUA_T_LINE */
|
|
|
|
} Value;
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1997-09-26 19:02:26 +04:00
|
|
|
|
|
|
|
typedef struct TObject {
|
|
|
|
lua_Type ttype;
|
|
|
|
Value value;
|
|
|
|
} TObject;
|
1997-09-16 23:25:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-11-04 20:23:12 +03:00
|
|
|
typedef struct GlobalVar {
|
|
|
|
TObject value;
|
|
|
|
struct GlobalVar *next;
|
|
|
|
struct TaggedString *name;
|
|
|
|
} GlobalVar;
|
|
|
|
|
|
|
|
|
1997-09-26 19:02:26 +04:00
|
|
|
/*
|
|
|
|
** String headers for string table
|
|
|
|
*/
|
|
|
|
typedef struct TaggedString {
|
|
|
|
union {
|
1999-11-04 20:23:12 +03:00
|
|
|
struct { /* for strings */
|
|
|
|
GlobalVar *gv; /* eventual global value with this name */
|
|
|
|
long len;
|
1998-03-06 19:54:42 +03:00
|
|
|
} s;
|
1999-11-04 20:23:12 +03:00
|
|
|
struct { /* for userdata */
|
1997-09-26 19:02:26 +04:00
|
|
|
int tag;
|
1999-11-04 20:23:12 +03:00
|
|
|
void *value;
|
1997-09-26 19:02:26 +04:00
|
|
|
} d;
|
|
|
|
} u;
|
1999-11-04 20:23:12 +03:00
|
|
|
struct TaggedString *nexthash; /* chain for hash table */
|
|
|
|
unsigned long hash;
|
|
|
|
int constindex; /* hint to reuse constants (= -1 if this is a userdata) */
|
1999-10-11 20:13:42 +04:00
|
|
|
unsigned char marked;
|
1997-09-26 19:02:26 +04:00
|
|
|
char str[1]; /* \0 byte already reserved */
|
|
|
|
} TaggedString;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
/*
|
|
|
|
** Function Prototypes
|
|
|
|
*/
|
|
|
|
typedef struct TProtoFunc {
|
1999-10-04 21:51:04 +04:00
|
|
|
struct TProtoFunc *next;
|
|
|
|
int marked;
|
1998-01-09 17:57:43 +03:00
|
|
|
struct TObject *consts;
|
|
|
|
int nconsts;
|
1997-09-16 23:25:59 +04:00
|
|
|
Byte *code; /* ends with opcode ENDCODE */
|
|
|
|
int lineDefined;
|
1999-03-05 00:23:39 +03:00
|
|
|
TaggedString *source;
|
1997-09-16 23:25:59 +04:00
|
|
|
struct LocVar *locvars; /* ends with line = -1 */
|
|
|
|
} TProtoFunc;
|
|
|
|
|
|
|
|
typedef struct LocVar {
|
|
|
|
TaggedString *varname; /* NULL signals end of scope */
|
|
|
|
int line;
|
|
|
|
} LocVar;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Macros to access structure members */
|
|
|
|
#define ttype(o) ((o)->ttype)
|
|
|
|
#define nvalue(o) ((o)->value.n)
|
|
|
|
#define svalue(o) ((o)->value.ts->str)
|
|
|
|
#define tsvalue(o) ((o)->value.ts)
|
|
|
|
#define clvalue(o) ((o)->value.cl)
|
|
|
|
#define avalue(o) ((o)->value.a)
|
|
|
|
#define fvalue(o) ((o)->value.f)
|
|
|
|
#define tfvalue(o) ((o)->value.tf)
|
|
|
|
|
1997-11-28 15:39:22 +03:00
|
|
|
#define protovalue(o) ((o)->value.cl->consts)
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1997-12-15 19:17:20 +03:00
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
/*
|
|
|
|
** Closures
|
|
|
|
*/
|
|
|
|
typedef struct Closure {
|
1999-10-04 21:51:04 +04:00
|
|
|
struct Closure *next;
|
|
|
|
int marked;
|
1999-12-27 20:33:22 +03:00
|
|
|
int nelems; /* not including the first one (always the prototype) */
|
1997-09-16 23:25:59 +04:00
|
|
|
TObject consts[1]; /* at least one for prototype */
|
|
|
|
} Closure;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct node {
|
1999-10-14 23:13:31 +04:00
|
|
|
TObject key;
|
1997-09-16 23:25:59 +04:00
|
|
|
TObject val;
|
1999-10-14 23:13:31 +04:00
|
|
|
struct node *next; /* for chaining */
|
1997-09-16 23:25:59 +04:00
|
|
|
} Node;
|
|
|
|
|
|
|
|
typedef struct Hash {
|
1999-10-14 23:13:31 +04:00
|
|
|
int htag;
|
|
|
|
Node *node;
|
1999-10-19 17:33:22 +04:00
|
|
|
int size;
|
1999-10-14 23:13:31 +04:00
|
|
|
Node *firstfree; /* this position is free; all positions after it are full */
|
1999-10-04 21:51:04 +04:00
|
|
|
struct Hash *next;
|
|
|
|
int marked;
|
1997-09-16 23:25:59 +04:00
|
|
|
} Hash;
|
|
|
|
|
|
|
|
|
1999-08-17 00:52:00 +04:00
|
|
|
extern const char *const luaO_typenames[];
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1999-12-14 21:33:29 +03:00
|
|
|
#define luaO_typename(o) luaO_typenames[-ttype(o)]
|
1998-07-12 20:11:55 +04:00
|
|
|
|
1999-11-26 21:59:20 +03:00
|
|
|
#define MINPOWER2 4 /* minimum size for "growing" vectors */
|
|
|
|
|
|
|
|
unsigned long luaO_power2 (unsigned long n);
|
1998-07-12 20:11:55 +04:00
|
|
|
|
1999-08-17 00:52:00 +04:00
|
|
|
extern const TObject luaO_nilobject;
|
1997-11-03 23:45:23 +03:00
|
|
|
|
1999-10-14 23:13:31 +04:00
|
|
|
|
1999-01-04 16:37:07 +03:00
|
|
|
#define luaO_equalObj(t1,t2) ((ttype(t1) != ttype(t2)) ? 0 \
|
|
|
|
: luaO_equalval(t1,t2))
|
1999-08-17 00:52:00 +04:00
|
|
|
int luaO_equalval (const TObject *t1, const TObject *t2);
|
1999-11-22 16:12:07 +03:00
|
|
|
int luaO_redimension (lua_State *L, int oldsize);
|
1999-09-07 00:34:18 +04:00
|
|
|
int luaO_str2d (const char *s, real *result);
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1997-12-26 21:38:16 +03:00
|
|
|
#ifdef OLD_ANSI
|
|
|
|
void luaO_memup (void *dest, void *src, int size);
|
|
|
|
void luaO_memdown (void *dest, void *src, int size);
|
|
|
|
#else
|
|
|
|
#include <string.h>
|
|
|
|
#define luaO_memup(d,s,n) memmove(d,s,n)
|
|
|
|
#define luaO_memdown(d,s,n) memmove(d,s,n)
|
|
|
|
#endif
|
1997-09-16 23:25:59 +04:00
|
|
|
|
|
|
|
#endif
|