aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c19
-rw-r--r--lgc.c9
-rw-r--r--lstate.c7
-rw-r--r--lstate.h6
-rw-r--r--lstring.c4
-rw-r--r--ltable.c4
-rw-r--r--ltm.c13
-rw-r--r--ltm.h6
8 files changed, 34 insertions, 34 deletions
diff --git a/lapi.c b/lapi.c
index c078160a..5c974e41 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.248 2003/10/20 12:25:23 roberto Exp roberto $ 2** $Id: lapi.c,v 1.249 2003/10/20 17:42:41 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -555,7 +555,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
555 mt = uvalue(obj)->uv.metatable; 555 mt = uvalue(obj)->uv.metatable;
556 break; 556 break;
557 } 557 }
558 if (mt == NULL || mt == hvalue(defaultmeta(L))) 558 if (mt == NULL)
559 res = 0; 559 res = 0;
560 else { 560 else {
561 sethvalue(L->top, mt); 561 sethvalue(L->top, mt);
@@ -634,21 +634,26 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
634 634
635 635
636LUA_API int lua_setmetatable (lua_State *L, int objindex) { 636LUA_API int lua_setmetatable (lua_State *L, int objindex) {
637 TObject *obj, *mt; 637 TObject *obj;
638 Table *mt;
638 int res = 1; 639 int res = 1;
639 lua_lock(L); 640 lua_lock(L);
640 api_checknelems(L, 1); 641 api_checknelems(L, 1);
641 obj = luaA_index(L, objindex); 642 obj = luaA_index(L, objindex);
642 api_checkvalidindex(L, obj); 643 api_checkvalidindex(L, obj);
643 mt = (!ttisnil(L->top - 1)) ? L->top - 1 : defaultmeta(L); 644 if (ttisnil(L->top - 1))
644 api_check(L, ttistable(mt)); 645 mt = NULL;
646 else {
647 api_check(L, ttistable(L->top - 1));
648 mt = hvalue(L->top - 1);
649 }
645 switch (ttype(obj)) { 650 switch (ttype(obj)) {
646 case LUA_TTABLE: { 651 case LUA_TTABLE: {
647 hvalue(obj)->metatable = hvalue(mt); /* write barrier */ 652 hvalue(obj)->metatable = mt; /* write barrier */
648 break; 653 break;
649 } 654 }
650 case LUA_TUSERDATA: { 655 case LUA_TUSERDATA: {
651 uvalue(obj)->uv.metatable = hvalue(mt); /* write barrier */ 656 uvalue(obj)->uv.metatable = mt; /* write barrier */
652 break; 657 break;
653 } 658 }
654 default: { 659 default: {
diff --git a/lgc.c b/lgc.c
index cb9fa289..f8fdcb4c 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.180 2003/11/19 19:41:57 roberto Exp roberto $ 2** $Id: lgc.c,v 1.181 2003/12/01 16:33:30 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -114,8 +114,9 @@ static void reallymarkobject (global_State *g, GCObject *o) {
114 return; 114 return;
115 } 115 }
116 case LUA_TUSERDATA: { 116 case LUA_TUSERDATA: {
117 Table *mt = gcotou(o)->uv.metatable;
117 white2black(o); /* userdata do not go to gray list */ 118 white2black(o); /* userdata do not go to gray list */
118 markobject(g, gcotou(o)->uv.metatable); 119 if (mt) markobject(g, mt);
119 return; 120 return;
120 } 121 }
121 case LUA_TFUNCTION: { 122 case LUA_TFUNCTION: {
@@ -191,7 +192,8 @@ static void traversetable (global_State *g, Table *h) {
191 int weakkey = 0; 192 int weakkey = 0;
192 int weakvalue = 0; 193 int weakvalue = 0;
193 const TObject *mode; 194 const TObject *mode;
194 markobject(g, h->metatable); 195 if (h->metatable)
196 markobject(g, h->metatable);
195 lua_assert(h->lsizenode || h->node == g->dummynode); 197 lua_assert(h->lsizenode || h->node == g->dummynode);
196 mode = gfasttm(g, h->metatable, TM_MODE); 198 mode = gfasttm(g, h->metatable, TM_MODE);
197 if (mode && ttisstring(mode)) { /* is there a weak mode? */ 199 if (mode && ttisstring(mode)) { /* is there a weak mode? */
@@ -534,7 +536,6 @@ static void markroot (lua_State *L) {
534 g->weak = NULL; 536 g->weak = NULL;
535 makewhite(valtogco(g->mainthread)); 537 makewhite(valtogco(g->mainthread));
536 markobject(g, g->mainthread); 538 markobject(g, g->mainthread);
537 markvalue(g, defaultmeta(L));
538 markvalue(g, registry(L)); 539 markvalue(g, registry(L));
539 if (L != g->mainthread) /* another thread is running? */ 540 if (L != g->mainthread) /* another thread is running? */
540 markobject(g, L); /* cannot collect it */ 541 markobject(g, L); /* cannot collect it */
diff --git a/lstate.c b/lstate.c
index 49c71719..40e29c6f 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.128 2003/11/18 14:55:11 roberto Exp roberto $ 2** $Id: lstate.c,v 1.129 2003/12/01 16:33:30 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -76,10 +76,6 @@ static void freestack (lua_State *L, lua_State *L1) {
76static void f_luaopen (lua_State *L, void *ud) { 76static void f_luaopen (lua_State *L, void *ud) {
77 UNUSED(ud); 77 UNUSED(ud);
78 stack_init(L, L); /* init stack */ 78 stack_init(L, L); /* init stack */
79 /* create default meta table with a dummy table, and then close the loop */
80 defaultmeta(L)->tt = LUA_TTABLE;
81 sethvalue(defaultmeta(L), luaH_new(L, 0, 0));
82 hvalue(defaultmeta(L))->metatable = hvalue(defaultmeta(L));
83 sethvalue(gt(L), luaH_new(L, 0, 4)); /* table of globals */ 79 sethvalue(gt(L), luaH_new(L, 0, 4)); /* table of globals */
84 sethvalue(registry(L), luaH_new(L, 4, 4)); /* registry */ 80 sethvalue(registry(L), luaH_new(L, 4, 4)); /* registry */
85 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ 81 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
@@ -161,7 +157,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
161 g->strt.size = 0; 157 g->strt.size = 0;
162 g->strt.nuse = 0; 158 g->strt.nuse = 0;
163 g->strt.hash = NULL; 159 g->strt.hash = NULL;
164 setnilvalue(defaultmeta(L));
165 setnilvalue(registry(L)); 160 setnilvalue(registry(L));
166 luaZ_initbuffer(L, &g->buff); 161 luaZ_initbuffer(L, &g->buff);
167 g->panic = NULL; 162 g->panic = NULL;
diff --git a/lstate.h b/lstate.h
index ed46fb1f..a62bcef8 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 1.113 2003/11/18 14:55:11 roberto Exp roberto $ 2** $Id: lstate.h,v 1.114 2003/12/01 16:33:30 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -42,9 +42,6 @@
42struct lua_longjmp; /* defined in ldo.c */ 42struct lua_longjmp; /* defined in ldo.c */
43 43
44 44
45/* default meta table (both for tables and udata) */
46#define defaultmeta(L) (&G(L)->_defaultmeta)
47
48/* table of globals */ 45/* table of globals */
49#define gt(L) (&L->_gt) 46#define gt(L) (&L->_gt)
50 47
@@ -113,7 +110,6 @@ typedef struct global_State {
113 lu_mem nblocks; /* number of `bytes' currently allocated */ 110 lu_mem nblocks; /* number of `bytes' currently allocated */
114 lua_CFunction panic; /* to be called in unprotected errors */ 111 lua_CFunction panic; /* to be called in unprotected errors */
115 TObject _registry; 112 TObject _registry;
116 TObject _defaultmeta;
117 struct lua_State *mainthread; 113 struct lua_State *mainthread;
118 Node dummynode[1]; /* common node array for all empty tables */ 114 Node dummynode[1]; /* common node array for all empty tables */
119 TString *tmname[TM_N]; /* array with tag-method names */ 115 TString *tmname[TM_N]; /* array with tag-method names */
diff --git a/lstring.c b/lstring.c
index 1b0a0050..e7e84609 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 1.79 2003/04/28 19:26:16 roberto Exp roberto $ 2** $Id: lstring.c,v 1.80 2003/11/17 19:50:05 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -94,7 +94,7 @@ Udata *luaS_newudata (lua_State *L, size_t s) {
94 u->uv.marked = 0; /* is not finalized */ 94 u->uv.marked = 0; /* is not finalized */
95 u->uv.tt = LUA_TUSERDATA; 95 u->uv.tt = LUA_TUSERDATA;
96 u->uv.len = s; 96 u->uv.len = s;
97 u->uv.metatable = hvalue(defaultmeta(L)); 97 u->uv.metatable = NULL;
98 /* chain it on udata list */ 98 /* chain it on udata list */
99 u->uv.next = G(L)->rootudata; 99 u->uv.next = G(L)->rootudata;
100 G(L)->rootudata = valtogco(u); 100 G(L)->rootudata = valtogco(u);
diff --git a/ltable.c b/ltable.c
index 8b55a1f5..ccd333f3 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.135 2003/08/26 12:04:13 roberto Exp roberto $ 2** $Id: ltable.c,v 1.136 2003/11/27 18:05:14 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -328,7 +328,7 @@ static void rehash (lua_State *L, Table *t) {
328Table *luaH_new (lua_State *L, int narray, int lnhash) { 328Table *luaH_new (lua_State *L, int narray, int lnhash) {
329 Table *t = luaM_new(L, Table); 329 Table *t = luaM_new(L, Table);
330 luaC_link(L, valtogco(t), LUA_TTABLE); 330 luaC_link(L, valtogco(t), LUA_TTABLE);
331 t->metatable = hvalue(defaultmeta(L)); 331 t->metatable = NULL;
332 t->flags = cast(lu_byte, ~0); 332 t->flags = cast(lu_byte, ~0);
333 /* temporary values (kept only if some malloc fails) */ 333 /* temporary values (kept only if some malloc fails) */
334 t->array = NULL; 334 t->array = NULL;
diff --git a/ltm.c b/ltm.c
index 5687e28b..b8fbb1f9 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.105 2002/12/04 17:38:31 roberto Exp roberto $ 2** $Id: ltm.c,v 1.106 2003/04/03 13:35:34 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -57,14 +57,17 @@ const TObject *luaT_gettm (Table *events, TMS event, TString *ename) {
57 57
58 58
59const TObject *luaT_gettmbyobj (lua_State *L, const TObject *o, TMS event) { 59const TObject *luaT_gettmbyobj (lua_State *L, const TObject *o, TMS event) {
60 TString *ename = G(L)->tmname[event]; 60 Table *mt;
61 switch (ttype(o)) { 61 switch (ttype(o)) {
62 case LUA_TTABLE: 62 case LUA_TTABLE:
63 return luaH_getstr(hvalue(o)->metatable, ename); 63 mt = hvalue(o)->metatable;
64 break;
64 case LUA_TUSERDATA: 65 case LUA_TUSERDATA:
65 return luaH_getstr(uvalue(o)->uv.metatable, ename); 66 mt = uvalue(o)->uv.metatable;
67 break;
66 default: 68 default:
67 return &luaO_nilobject; 69 mt = NULL;
68 } 70 }
71 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : &luaO_nilobject);
69} 72}
70 73
diff --git a/ltm.h b/ltm.h
index 4c56a093..d40bf6c5 100644
--- a/ltm.h
+++ b/ltm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.h,v 1.40 2002/09/19 20:12:47 roberto Exp roberto $ 2** $Id: ltm.h,v 1.41 2002/11/14 11:51:50 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -36,8 +36,8 @@ typedef enum {
36 36
37 37
38 38
39#define gfasttm(g,et,e) \ 39#define gfasttm(g,et,e) ((et) == NULL ? NULL : \
40 (((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 40 ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
41 41
42#define fasttm(l,et,e) gfasttm(G(l), et, e) 42#define fasttm(l,et,e) gfasttm(G(l), et, e)
43 43