1997-09-17 03:25:59 +08:00
|
|
|
/*
|
1997-12-24 03:24:19 +08:00
|
|
|
** $Id: lobject.h,v 1.11 1997/12/15 16:17:20 roberto Exp roberto $
|
1997-09-17 03:25:59 +08:00
|
|
|
** Type definitions for Lua objects
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lobject_h
|
|
|
|
#define lobject_h
|
|
|
|
|
|
|
|
|
|
|
|
#include "lua.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
1997-12-24 03:24:19 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
** "real" is the type "number" of Lua
|
|
|
|
** GREP LUA_NUMBER to change that
|
|
|
|
*/
|
1997-09-17 03:25:59 +08:00
|
|
|
#ifndef real
|
|
|
|
#define real float
|
|
|
|
#endif
|
|
|
|
|
1997-12-24 03:24:19 +08:00
|
|
|
|
1997-09-17 03:25:59 +08:00
|
|
|
#define Byte lua_Byte /* some systems have Byte as a predefined type */
|
|
|
|
typedef unsigned char Byte; /* unsigned 8 bits */
|
|
|
|
|
|
|
|
#define Word lua_Word /* some systems have Word as a predefined type */
|
|
|
|
typedef unsigned short Word; /* unsigned 16 bits */
|
|
|
|
|
|
|
|
#define MAX_WORD (USHRT_MAX-2) /* maximum value of a word (-2 for safety) */
|
|
|
|
#define MAX_INT (INT_MAX-2) /* maximum value of a int (-2 for safety) */
|
|
|
|
|
|
|
|
typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hashing) */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-09-26 23:02:26 +08:00
|
|
|
** Lua TYPES
|
|
|
|
** WARNING: if you change the order of this enumeration,
|
|
|
|
** grep "ORDER LUA_T"
|
1997-09-17 03:25:59 +08:00
|
|
|
*/
|
1997-09-26 23:02:26 +08:00
|
|
|
typedef enum {
|
1997-10-17 04:07:40 +08:00
|
|
|
LUA_T_USERDATA = 0, /* tag default for userdata */
|
|
|
|
LUA_T_NUMBER = -1, /* fixed tag for numbers */
|
|
|
|
LUA_T_STRING = -2, /* fixed tag for strings */
|
|
|
|
LUA_T_ARRAY = -3, /* tag default for tables (or arrays) */
|
1997-10-25 01:17:24 +08:00
|
|
|
LUA_T_PROTO = -4, /* fixed tag for functions */
|
|
|
|
LUA_T_CPROTO = -5, /* fixed tag for Cfunctions */
|
1997-10-17 04:07:40 +08:00
|
|
|
LUA_T_NIL = -6, /* last "pre-defined" tag */
|
1997-12-16 00:17:20 +08:00
|
|
|
LUA_T_CLOSURE = -7,
|
|
|
|
LUA_T_CLMARK = -8, /* mark for closures */
|
|
|
|
LUA_T_PMARK = -9, /* mark for Lua prototypes */
|
|
|
|
LUA_T_CMARK = -10, /* mark for C prototypes */
|
|
|
|
LUA_T_LINE = -11
|
1997-09-26 23:02:26 +08:00
|
|
|
} lua_Type;
|
1997-09-17 03:25:59 +08:00
|
|
|
|
1997-09-26 23:02:26 +08:00
|
|
|
#define NUM_TYPES 11
|
1997-10-17 04:07:40 +08:00
|
|
|
#define NUM_TAGS 7
|
1997-09-26 23:02:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
typedef union {
|
1997-12-16 00:17:20 +08:00
|
|
|
lua_CFunction f; /* LUA_T_CPROTO, LUA_T_CMARK */
|
1997-09-26 23:02:26 +08:00
|
|
|
real n; /* LUA_T_NUMBER */
|
|
|
|
struct TaggedString *ts; /* LUA_T_STRING, LUA_T_USERDATA */
|
1997-12-16 00:17:20 +08:00
|
|
|
struct TProtoFunc *tf; /* LUA_T_PROTO, LUA_T_PMARK */
|
|
|
|
struct Closure *cl; /* LUA_T_CLOSURE, LUA_T_CLMARK */
|
1997-09-26 23:02:26 +08:00
|
|
|
struct Hash *a; /* LUA_T_ARRAY */
|
|
|
|
int i; /* LUA_T_LINE */
|
|
|
|
} Value;
|
1997-09-17 03:25:59 +08:00
|
|
|
|
1997-09-26 23:02:26 +08:00
|
|
|
|
|
|
|
typedef struct TObject {
|
|
|
|
lua_Type ttype;
|
|
|
|
Value value;
|
|
|
|
} TObject;
|
1997-09-17 03:25:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** generic header for garbage collector lists
|
|
|
|
*/
|
|
|
|
typedef struct GCnode {
|
|
|
|
struct GCnode *next;
|
|
|
|
int marked;
|
|
|
|
} GCnode;
|
|
|
|
|
|
|
|
|
1997-09-26 23:02:26 +08:00
|
|
|
/*
|
|
|
|
** String headers for string table
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct TaggedString {
|
|
|
|
GCnode head;
|
|
|
|
int constindex; /* hint to reuse constants (= -1 if this is a userdata) */
|
|
|
|
unsigned long hash;
|
|
|
|
union {
|
|
|
|
TObject globalval;
|
|
|
|
struct {
|
|
|
|
void *v; /* if this is a userdata, here is its value */
|
|
|
|
int tag;
|
|
|
|
} d;
|
|
|
|
} u;
|
|
|
|
char str[1]; /* \0 byte already reserved */
|
|
|
|
} TaggedString;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-09-17 03:25:59 +08:00
|
|
|
/*
|
|
|
|
** Function Prototypes
|
|
|
|
*/
|
|
|
|
typedef struct TProtoFunc {
|
|
|
|
GCnode head;
|
|
|
|
Byte *code; /* ends with opcode ENDCODE */
|
|
|
|
int lineDefined;
|
|
|
|
TaggedString *fileName;
|
|
|
|
struct TObject *consts;
|
|
|
|
int nconsts;
|
|
|
|
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 20:39:22 +08:00
|
|
|
#define protovalue(o) ((o)->value.cl->consts)
|
1997-09-17 03:25:59 +08:00
|
|
|
|
1997-12-16 00:17:20 +08:00
|
|
|
|
1997-09-17 03:25:59 +08:00
|
|
|
/*
|
|
|
|
** Closures
|
|
|
|
*/
|
|
|
|
typedef struct Closure {
|
|
|
|
GCnode head;
|
1997-10-16 18:59:34 +08:00
|
|
|
int nelems; /* not included the first one (always the prototype) */
|
1997-09-17 03:25:59 +08:00
|
|
|
TObject consts[1]; /* at least one for prototype */
|
|
|
|
} Closure;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct node {
|
|
|
|
TObject ref;
|
|
|
|
TObject val;
|
|
|
|
} Node;
|
|
|
|
|
|
|
|
typedef struct Hash {
|
|
|
|
GCnode head;
|
|
|
|
Node *node;
|
|
|
|
int nhash;
|
|
|
|
int nuse;
|
|
|
|
int htag;
|
|
|
|
} Hash;
|
|
|
|
|
|
|
|
|
1997-10-24 00:26:37 +08:00
|
|
|
/*
|
|
|
|
** a gross estimation of number of memory "blocks" allocated
|
|
|
|
** (a block is *roughly* 32 bytes)
|
|
|
|
*/
|
|
|
|
|
1997-09-17 03:25:59 +08:00
|
|
|
extern char *luaO_typenames[];
|
|
|
|
|
1997-11-04 04:45:23 +08:00
|
|
|
extern TObject luaO_nilobject;
|
|
|
|
|
1997-09-17 03:25:59 +08:00
|
|
|
int luaO_equalObj (TObject *t1, TObject *t2);
|
|
|
|
int luaO_redimension (int oldsize);
|
|
|
|
int luaO_findstring (char *name, char *list[]);
|
1997-09-27 00:46:20 +08:00
|
|
|
void luaO_insertlist (GCnode *root, GCnode *node);
|
1997-09-17 03:25:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|