|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
-** $Id: lobject.h,v 1.148 2002/10/16 20:40:58 roberto Exp roberto $
|
|
|
|
|
|
+** $Id: lobject.h,v 1.149 2002/10/22 17:18:28 roberto Exp roberto $
|
|
** Type definitions for Lua objects
|
|
** Type definitions for Lua objects
|
|
** See Copyright Notice in lua.h
|
|
** See Copyright Notice in lua.h
|
|
*/
|
|
*/
|
|
@@ -13,7 +13,7 @@
|
|
|
|
|
|
|
|
|
|
/* tags for values visible from Lua */
|
|
/* tags for values visible from Lua */
|
|
-#define NUM_TAGS LUA_TUSERDATA
|
|
|
|
|
|
+#define NUM_TAGS LUA_TTHREAD
|
|
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -23,23 +23,34 @@
|
|
#define LUA_TUPVAL (NUM_TAGS+2)
|
|
#define LUA_TUPVAL (NUM_TAGS+2)
|
|
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+** Union of all collectable objects
|
|
|
|
+*/
|
|
|
|
+typedef union GCObject GCObject;
|
|
|
|
+
|
|
|
|
+
|
|
/*
|
|
/*
|
|
** Common header for all collectable objects
|
|
** Common header for all collectable objects
|
|
*/
|
|
*/
|
|
typedef struct GCheader {
|
|
typedef struct GCheader {
|
|
- union GCObject *next; /* pointer to next object */
|
|
|
|
|
|
+ GCObject *next; /* pointer to next object */
|
|
lu_byte tt; /* object type */
|
|
lu_byte tt; /* object type */
|
|
lu_byte marked; /* GC informations */
|
|
lu_byte marked; /* GC informations */
|
|
} GCheader;
|
|
} GCheader;
|
|
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+** common header in macro form, to be included in other objects
|
|
|
|
+*/
|
|
|
|
+#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
** Union of all Lua values
|
|
** Union of all Lua values
|
|
*/
|
|
*/
|
|
typedef union {
|
|
typedef union {
|
|
- union GCObject *gc;
|
|
|
|
|
|
+ GCObject *gc;
|
|
void *p;
|
|
void *p;
|
|
lua_Number n;
|
|
lua_Number n;
|
|
int b;
|
|
int b;
|
|
@@ -63,6 +74,7 @@ typedef struct lua_TObject {
|
|
#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION)
|
|
#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION)
|
|
#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN)
|
|
#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN)
|
|
#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA)
|
|
#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA)
|
|
|
|
+#define ttisthread(o) (ttype(o) == LUA_TTHREAD)
|
|
#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA)
|
|
#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA)
|
|
|
|
|
|
/* Macros to access values */
|
|
/* Macros to access values */
|
|
@@ -75,6 +87,7 @@ typedef struct lua_TObject {
|
|
#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl)
|
|
#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl)
|
|
#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h)
|
|
#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h)
|
|
#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b)
|
|
#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b)
|
|
|
|
+#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th)
|
|
|
|
|
|
#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
|
|
#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
|
|
|
|
|
|
@@ -101,6 +114,11 @@ typedef struct lua_TObject {
|
|
i_o->value.gc=cast(GCObject *, (x)); \
|
|
i_o->value.gc=cast(GCObject *, (x)); \
|
|
lua_assert(i_o->value.gc->gch.tt == LUA_TUSERDATA); }
|
|
lua_assert(i_o->value.gc->gch.tt == LUA_TUSERDATA); }
|
|
|
|
|
|
|
|
+#define setthvalue(obj,x) \
|
|
|
|
+ { TObject *i_o=(obj); i_o->tt=LUA_TTHREAD; \
|
|
|
|
+ i_o->value.gc=cast(GCObject *, (x)); \
|
|
|
|
+ lua_assert(i_o->value.gc->gch.tt == LUA_TTHREAD); }
|
|
|
|
+
|
|
#define setclvalue(obj,x) \
|
|
#define setclvalue(obj,x) \
|
|
{ TObject *i_o=(obj); i_o->tt=LUA_TFUNCTION; \
|
|
{ TObject *i_o=(obj); i_o->tt=LUA_TFUNCTION; \
|
|
i_o->value.gc=cast(GCObject *, (x)); \
|
|
i_o->value.gc=cast(GCObject *, (x)); \
|
|
@@ -142,9 +160,7 @@ typedef TObject *StkId; /* index to stack elements */
|
|
typedef union TString {
|
|
typedef union TString {
|
|
L_Umaxalign dummy; /* ensures maximum alignment for strings */
|
|
L_Umaxalign dummy; /* ensures maximum alignment for strings */
|
|
struct {
|
|
struct {
|
|
- union GCObject *next; /* pointer to next object */
|
|
|
|
- lu_byte tt; /* object type */
|
|
|
|
- lu_byte marked; /* GC informations */
|
|
|
|
|
|
+ CommonHeader;
|
|
lu_byte reserved;
|
|
lu_byte reserved;
|
|
lu_hash hash;
|
|
lu_hash hash;
|
|
size_t len;
|
|
size_t len;
|
|
@@ -160,9 +176,7 @@ typedef union TString {
|
|
typedef union Udata {
|
|
typedef union Udata {
|
|
L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
|
|
L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
|
|
struct {
|
|
struct {
|
|
- union GCObject *next; /* pointer to next object */
|
|
|
|
- lu_byte tt; /* object type */
|
|
|
|
- lu_byte marked; /* GC informations */
|
|
|
|
|
|
+ CommonHeader;
|
|
struct Table *metatable;
|
|
struct Table *metatable;
|
|
size_t len;
|
|
size_t len;
|
|
} uv;
|
|
} uv;
|
|
@@ -175,9 +189,7 @@ typedef union Udata {
|
|
** Function Prototypes
|
|
** Function Prototypes
|
|
*/
|
|
*/
|
|
typedef struct Proto {
|
|
typedef struct Proto {
|
|
- union GCObject *next; /* pointer to next object */
|
|
|
|
- lu_byte tt; /* object type */
|
|
|
|
- lu_byte marked; /* GC informations */
|
|
|
|
|
|
+ CommonHeader;
|
|
TObject *k; /* constants used by the function */
|
|
TObject *k; /* constants used by the function */
|
|
Instruction *code;
|
|
Instruction *code;
|
|
struct Proto **p; /* functions defined inside the function */
|
|
struct Proto **p; /* functions defined inside the function */
|
|
@@ -210,9 +222,7 @@ typedef struct LocVar {
|
|
*/
|
|
*/
|
|
|
|
|
|
typedef struct UpVal {
|
|
typedef struct UpVal {
|
|
- union GCObject *next; /* pointer to next object */
|
|
|
|
- lu_byte tt; /* object type */
|
|
|
|
- lu_byte marked; /* GC informations */
|
|
|
|
|
|
+ CommonHeader;
|
|
TObject *v; /* points to stack or to its own value */
|
|
TObject *v; /* points to stack or to its own value */
|
|
TObject value; /* the value (when closed) */
|
|
TObject value; /* the value (when closed) */
|
|
} UpVal;
|
|
} UpVal;
|
|
@@ -223,9 +233,7 @@ typedef struct UpVal {
|
|
*/
|
|
*/
|
|
|
|
|
|
typedef struct CClosure {
|
|
typedef struct CClosure {
|
|
- union GCObject *next; /* pointer to next object */
|
|
|
|
- lu_byte tt; /* object type */
|
|
|
|
- lu_byte marked; /* GC informations */
|
|
|
|
|
|
+ CommonHeader;
|
|
lu_byte isC; /* 0 for Lua functions, 1 for C functions */
|
|
lu_byte isC; /* 0 for Lua functions, 1 for C functions */
|
|
lu_byte nupvalues;
|
|
lu_byte nupvalues;
|
|
lua_CFunction f;
|
|
lua_CFunction f;
|
|
@@ -234,9 +242,7 @@ typedef struct CClosure {
|
|
|
|
|
|
|
|
|
|
typedef struct LClosure {
|
|
typedef struct LClosure {
|
|
- union GCObject *next; /* pointer to next object */
|
|
|
|
- lu_byte tt; /* object type */
|
|
|
|
- lu_byte marked; /* GC informations */
|
|
|
|
|
|
+ CommonHeader;
|
|
lu_byte isC;
|
|
lu_byte isC;
|
|
lu_byte nupvalues; /* first five fields must be equal to CClosure!! */
|
|
lu_byte nupvalues; /* first five fields must be equal to CClosure!! */
|
|
struct Proto *p;
|
|
struct Proto *p;
|
|
@@ -267,9 +273,7 @@ typedef struct Node {
|
|
|
|
|
|
|
|
|
|
typedef struct Table {
|
|
typedef struct Table {
|
|
- union GCObject *next; /* pointer to next object */
|
|
|
|
- lu_byte tt; /* object type */
|
|
|
|
- lu_byte marked; /* GC informations */
|
|
|
|
|
|
+ CommonHeader;
|
|
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
|
|
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
|
|
lu_byte mode;
|
|
lu_byte mode;
|
|
lu_byte lsizenode; /* log2 of size of `node' array */
|
|
lu_byte lsizenode; /* log2 of size of `node' array */
|
|
@@ -298,19 +302,6 @@ typedef struct Table {
|
|
#define sizearray(t) ((t)->sizearray)
|
|
#define sizearray(t) ((t)->sizearray)
|
|
|
|
|
|
|
|
|
|
-/*
|
|
|
|
-** Union of all collectable objects
|
|
|
|
-*/
|
|
|
|
-typedef union GCObject {
|
|
|
|
- GCheader gch;
|
|
|
|
- union TString ts;
|
|
|
|
- union Udata u;
|
|
|
|
- union Closure cl;
|
|
|
|
- struct Table h;
|
|
|
|
- struct Proto p;
|
|
|
|
- struct UpVal uv;
|
|
|
|
-} GCObject;
|
|
|
|
-
|
|
|
|
|
|
|
|
extern const TObject luaO_nilobject;
|
|
extern const TObject luaO_nilobject;
|
|
|
|
|