aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c29
-rw-r--r--ldebug.c4
-rw-r--r--lgc.c4
-rw-r--r--lstate.c4
-rw-r--r--lstate.h4
-rw-r--r--lua.h13
-rw-r--r--lvm.c8
7 files changed, 31 insertions, 35 deletions
diff --git a/lapi.c b/lapi.c
index c0212e79..36b77abe 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.157 2001/10/25 19:14:14 roberto Exp $ 2** $Id: lapi.c,v 1.158 2001/10/31 19:40:14 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*/
@@ -44,13 +44,16 @@ static TObject *negindex (lua_State *L, int index) {
44 if (index > LUA_REGISTRYINDEX) { 44 if (index > LUA_REGISTRYINDEX) {
45 api_check(L, index != 0 && -index <= L->top - L->ci->base); 45 api_check(L, index != 0 && -index <= L->top - L->ci->base);
46 return L->top+index; 46 return L->top+index;
47 } else if (index == LUA_REGISTRYINDEX) /* pseudo-indices */ 47 }
48 return &G(L)->registry; 48 else switch (index) { /* pseudo-indices */
49 else { 49 case LUA_REGISTRYINDEX: return &G(L)->registry;
50 TObject *func = (L->ci->base - 1); 50 case LUA_GLOBALSINDEX: return &L->gt;
51 index = LUA_REGISTRYINDEX - index; 51 default: {
52 api_check(L, iscfunction(func) && index <= clvalue(func)->c.nupvalues); 52 TObject *func = (L->ci->base - 1);
53 return &clvalue(func)->c.upvalue[index-1]; 53 index = LUA_GLOBALSINDEX - index;
54 api_check(L, iscfunction(func) && index <= clvalue(func)->c.nupvalues);
55 return &clvalue(func)->c.upvalue[index-1];
56 }
54 } 57 }
55} 58}
56 59
@@ -381,14 +384,6 @@ LUA_API void lua_rawgeti (lua_State *L, int index, int n) {
381} 384}
382 385
383 386
384LUA_API void lua_getglobals (lua_State *L) {
385 lua_lock(L);
386 sethvalue(L->top, L->gt);
387 api_incr_top(L);
388 lua_unlock(L);
389}
390
391
392LUA_API void lua_newtable (lua_State *L) { 387LUA_API void lua_newtable (lua_State *L) {
393 lua_lock(L); 388 lua_lock(L);
394 sethvalue(L->top, luaH_new(L, 0, 0)); 389 sethvalue(L->top, luaH_new(L, 0, 0));
@@ -453,7 +448,7 @@ LUA_API void lua_setglobals (lua_State *L) {
453 api_checknelems(L, 1); 448 api_checknelems(L, 1);
454 newtable = --L->top; 449 newtable = --L->top;
455 api_check(L, ttype(newtable) == LUA_TTABLE); 450 api_check(L, ttype(newtable) == LUA_TTABLE);
456 L->gt = hvalue(newtable); 451 setobj(&L->gt, newtable);
457 lua_unlock(L); 452 lua_unlock(L);
458} 453}
459 454
diff --git a/ldebug.c b/ldebug.c
index 5adab2af..7b568e60 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.90 2001/10/02 16:45:03 roberto Exp $ 2** $Id: ldebug.c,v 1.91 2001/10/25 19:14:14 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -221,7 +221,7 @@ static const l_char *travtagmethods (global_State *G, const TObject *o) {
221 221
222 222
223static const l_char *travglobals (lua_State *L, const TObject *o) { 223static const l_char *travglobals (lua_State *L, const TObject *o) {
224 Table *g = L->gt; 224 Table *g = hvalue(&L->gt);
225 int i = sizenode(g); 225 int i = sizenode(g);
226 while (i--) { 226 while (i--) {
227 Node *n = node(g, i); 227 Node *n = node(g, i);
diff --git a/lgc.c b/lgc.c
index cf9148e9..abace987 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.113 2001/10/17 21:12:57 roberto Exp $ 2** $Id: lgc.c,v 1.114 2001/10/25 19:14:14 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*/
@@ -112,7 +112,7 @@ static void markstacks (lua_State *L, GCState *st) {
112 lua_State *L1 = L; 112 lua_State *L1 = L;
113 do { /* for each thread */ 113 do { /* for each thread */
114 StkId o, lim; 114 StkId o, lim;
115 marktable(st, L1->gt); /* mark table of globals */ 115 markobject(st, &L1->gt); /* mark table of globals */
116 for (o=L1->stack; o<L1->top; o++) 116 for (o=L1->stack; o<L1->top; o++)
117 markobject(st, o); 117 markobject(st, o);
118 lim = (L1->stack_last - L1->ci->base > MAXSTACK) ? L1->ci->base+MAXSTACK 118 lim = (L1->stack_last - L1->ci->base > MAXSTACK) ? L1->ci->base+MAXSTACK
diff --git a/lstate.c b/lstate.c
index 1fe006ae..98190c22 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.69 2001/10/17 21:12:57 roberto Exp $ 2** $Id: lstate.c,v 1.70 2001/10/25 19:14:14 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*/
@@ -64,7 +64,7 @@ static void f_luaopen (lua_State *L, void *ud) {
64 G(L)->ntag = 0; 64 G(L)->ntag = 0;
65 G(L)->nblocks = sizeof(lua_State) + sizeof(global_State); 65 G(L)->nblocks = sizeof(lua_State) + sizeof(global_State);
66 luaD_init(L, so->stacksize); /* init stack */ 66 luaD_init(L, so->stacksize); /* init stack */
67 L->gt = luaH_new(L, 0, 4); /* table of globals */ 67 sethvalue(&L->gt, luaH_new(L, 0, 4)); /* table of globals */
68 G(L)->type2tag = luaH_new(L, 0, 3); 68 G(L)->type2tag = luaH_new(L, 0, 3);
69 sethvalue(&G(L)->registry, luaH_new(L, 0, 0)); 69 sethvalue(&G(L)->registry, luaH_new(L, 0, 0));
70 luaS_resize(L, 4); /* initial size of string table */ 70 luaS_resize(L, 4); /* initial size of string table */
diff --git a/lstate.h b/lstate.h
index 4339d73d..4b4c60e7 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 1.61 2001/10/17 21:12:57 roberto Exp $ 2** $Id: lstate.h,v 1.62 2001/10/25 19:12:21 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*/
@@ -80,7 +80,7 @@ struct lua_State {
80 StkId top; /* first free slot in the stack */ 80 StkId top; /* first free slot in the stack */
81 CallInfo *ci; /* call info for current function */ 81 CallInfo *ci; /* call info for current function */
82 StkId stack_last; /* last free slot in the stack */ 82 StkId stack_last; /* last free slot in the stack */
83 Table *gt; /* table for globals */ 83 TObject gt; /* table for globals */
84 global_State *G; 84 global_State *G;
85 StkId stack; /* stack base */ 85 StkId stack; /* stack base */
86 int stacksize; 86 int stacksize;
diff --git a/lua.h b/lua.h
index 1691b07f..9cc3f081 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.105 2001/10/17 21:12:57 roberto Exp $ 2** $Id: lua.h,v 1.106 2001/10/31 19:40:14 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
5** e-mail: info@lua.org 5** e-mail: info@lua.org
@@ -30,11 +30,12 @@
30#define LUA_MULTRET (-1) 30#define LUA_MULTRET (-1)
31 31
32 32
33/* pseudo-index for registry */ 33/*
34** pseudo-indices
35*/
34#define LUA_REGISTRYINDEX (-10000) 36#define LUA_REGISTRYINDEX (-10000)
35 37#define LUA_GLOBALSINDEX (-10001)
36/* pseudo-indices for upvalues */ 38#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
37#define lua_upvalueindex(i) (LUA_REGISTRYINDEX-(i))
38 39
39 40
40/* error codes for `lua_do*' and the like */ 41/* error codes for `lua_do*' and the like */
@@ -160,7 +161,6 @@ LUA_API void lua_getglobal (lua_State *L, const lua_char *name);
160LUA_API void lua_gettable (lua_State *L, int index); 161LUA_API void lua_gettable (lua_State *L, int index);
161LUA_API void lua_rawget (lua_State *L, int index); 162LUA_API void lua_rawget (lua_State *L, int index);
162LUA_API void lua_rawgeti (lua_State *L, int index, int n); 163LUA_API void lua_rawgeti (lua_State *L, int index, int n);
163LUA_API void lua_getglobals (lua_State *L);
164LUA_API void lua_gettagmethod (lua_State *L, int tag, const lua_char *event); 164LUA_API void lua_gettagmethod (lua_State *L, int tag, const lua_char *event);
165LUA_API void lua_newtable (lua_State *L); 165LUA_API void lua_newtable (lua_State *L);
166LUA_API void lua_getweakregistry (lua_State *L); 166LUA_API void lua_getweakregistry (lua_State *L);
@@ -244,6 +244,7 @@ LUA_API int lua_getweakmode (lua_State *L, int index);
244 (sizeof(s)/sizeof(lua_char))-1) 244 (sizeof(s)/sizeof(lua_char))-1)
245 245
246#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX); 246#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX);
247#define lua_getglobals(L) lua_pushvalue(L, LUA_GLOBALSINDEX);
247 248
248 249
249 250
diff --git a/lvm.c b/lvm.c
index 29877135..6f0d9ab7 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.195 2001/10/02 16:45:03 roberto Exp $ 2** $Id: lvm.c,v 1.196 2001/10/25 19:14:14 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -176,7 +176,7 @@ void luaV_settable (lua_State *L, StkId t, TObject *key, StkId val) {
176 176
177 177
178void luaV_getglobal (lua_State *L, TString *name, StkId res) { 178void luaV_getglobal (lua_State *L, TString *name, StkId res) {
179 const TObject *value = luaH_getstr(L->gt, name); 179 const TObject *value = luaH_getstr(hvalue(&L->gt), name);
180 Closure *tm; 180 Closure *tm;
181 if (!HAS_TM_GETGLOBAL(L, ttype(value)) || /* is there a tag method? */ 181 if (!HAS_TM_GETGLOBAL(L, ttype(value)) || /* is there a tag method? */
182 (tm = luaT_gettmbyObj(G(L), value, TM_GETGLOBAL)) == NULL) { 182 (tm = luaT_gettmbyObj(G(L), value, TM_GETGLOBAL)) == NULL) {
@@ -188,12 +188,12 @@ void luaV_getglobal (lua_State *L, TString *name, StkId res) {
188 188
189 189
190void luaV_setglobal (lua_State *L, TString *name, StkId val) { 190void luaV_setglobal (lua_State *L, TString *name, StkId val) {
191 const TObject *oldvalue = luaH_getstr(L->gt, name); 191 const TObject *oldvalue = luaH_getstr(hvalue(&L->gt), name);
192 Closure *tm; 192 Closure *tm;
193 if (!HAS_TM_SETGLOBAL(L, ttype(oldvalue)) || /* no tag methods? */ 193 if (!HAS_TM_SETGLOBAL(L, ttype(oldvalue)) || /* no tag methods? */
194 (tm = luaT_gettmbyObj(G(L), oldvalue, TM_SETGLOBAL)) == NULL) { 194 (tm = luaT_gettmbyObj(G(L), oldvalue, TM_SETGLOBAL)) == NULL) {
195 if (oldvalue == &luaO_nilobject) 195 if (oldvalue == &luaO_nilobject)
196 luaH_setstr(L, L->gt, name, val); /* raw set */ 196 luaH_setstr(L, hvalue(&L->gt), name, val); /* raw set */
197 else 197 else
198 settableval(oldvalue, val); /* warning: tricky optimization! */ 198 settableval(oldvalue, val); /* warning: tricky optimization! */
199 } 199 }