Browse Source

back to the basics (well-behaved variant record...)

v5-2
Roberto Ierusalimschy 24 years ago
parent
commit
1f9e3731d1
  1. 4
      lgc.c
  2. 30
      lobject.h
  3. 6
      ltable.h

4
lgc.c

@ -1,5 +1,5 @@
/*
** $Id: lgc.c,v 1.85 2001/02/02 15:13:05 roberto Exp roberto $
** $Id: lgc.c,v 1.86 2001/02/02 16:23:20 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@ -147,7 +147,7 @@ static void traversetable (GCState *st, Hash *h) {
Node *n = node(h, i);
if (ttype(val(n)) == LUA_TNIL) {
if (ttype_key(n) != LUA_TNIL)
n->key_value.v = NULL; /* dead key; remove it */
n->key_value.ts = NULL; /* dead key; remove it */
}
else {
lua_assert(ttype_key(n) != LUA_TNIL);

30
lobject.h

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 1.92 2001/02/01 17:40:48 roberto Exp roberto $
** $Id: lobject.h,v 1.93 2001/02/02 15:13:05 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -36,7 +36,10 @@
typedef union {
void *v;
struct TString *ts;
struct Closure *cl;
struct Hash *h;
struct CallInfo *info;
lua_Number n; /* LUA_TNUMBER */
} Value;
@ -50,10 +53,10 @@ typedef struct lua_TObject {
/* Macros to access values */
#define ttype(o) ((o)->tt)
#define nvalue(o) ((o)->value.n)
#define tsvalue(o) ((struct TString *)(o)->value.v)
#define clvalue(o) ((struct Closure *)(o)->value.v)
#define hvalue(o) ((struct Hash *)(o)->value.v)
#define infovalue(o) ((struct CallInfo *)(o)->value.v)
#define tsvalue(o) ((o)->value.ts)
#define clvalue(o) ((o)->value.cl)
#define hvalue(o) ((o)->value.h)
#define infovalue(o) ((o)->value.info)
#define svalue(o) (tsvalue(o)->str)
@ -62,24 +65,19 @@ typedef struct lua_TObject {
{ TObject *_o=(obj); _o->tt=LUA_TNUMBER; _o->value.n=(x); }
#define setsvalue(obj,x) \
{ TObject *_o=(obj); struct TString *_v=(x); \
_o->tt=LUA_TSTRING; _o->value.v=_v; }
{ TObject *_o=(obj); _o->tt=LUA_TSTRING; _o->value.ts=(x); }
#define setuvalue(obj,x) \
{ TObject *_o=(obj); struct TString *_v=(x); \
_o->tt=LUA_TUSERDATA; _o->value.v=_v; }
{ TObject *_o=(obj); _o->tt=LUA_TUSERDATA; _o->value.ts=(x); }
#define setclvalue(obj,x) \
{ TObject *_o=(obj); struct Closure *_v=(x); \
_o->tt=LUA_TFUNCTION; _o->value.v=_v; }
{ TObject *_o=(obj); _o->tt=LUA_TFUNCTION; _o->value.cl=(x); }
#define sethvalue(obj,x) \
{ TObject *_o=(obj); struct Hash *_v=(x); \
_o->tt=LUA_TTABLE; _o->value.v=_v; }
{ TObject *_o=(obj); _o->tt=LUA_TTABLE; _o->value.h=(x); }
#define setivalue(obj,x) \
{ TObject *_o=(obj); struct CallInfo *_v=(x); \
_o->tt=LUA_TMARK; _o->value.v=_v; }
{ TObject *_o=(obj); _o->tt=LUA_TMARK; _o->value.info=(x); }
#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)

6
ltable.h

@ -1,5 +1,5 @@
/*
** $Id: ltable.h,v 1.30 2001/01/29 13:02:20 roberto Exp roberto $
** $Id: ltable.h,v 1.31 2001/01/29 17:17:26 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -15,13 +15,13 @@
#define ttype_key(_n) ((_n)->key_tt)
#define nvalue_key(_n) ((_n)->key_value.n)
#define tsvalue_key(_n) ((TString *)(_n)->key_value.v)
#define tsvalue_key(_n) ((_n)->key_value.ts)
#define setkey2obj(_o,_k) \
((_o)->tt = ttype_key(_k), (_o)->value = (_k)->key_value)
#define setobj2key(_k,_o) \
(ttype_key(_k) = (_o)->tt, (_k)->key_value = (_o)->value)
#define luaH_get(_t,_k) luaH_set(NULL,_t,_k)
#define luaH_get(_t,_k) luaH_set(NULL,_t,_k)
#define luaH_getnum(_t,_k) luaH_setnum(NULL,_t,_k)
#define luaH_getstr(_t,_k) luaH_setstr(NULL,_t,_k)

Loading…
Cancel
Save