summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-18 16:32:39 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-18 16:32:39 -0200
commitde79e7fc586c0b60a04823c0e930b227af2828d8 (patch)
treee48cd57eba16106100fb18e2bd2c1ab19f841347
parent8b5b42563c317f83318a0386551f0f0252e387dc (diff)
downloadlua-de79e7fc586c0b60a04823c0e930b227af2828d8.tar.gz
lua-de79e7fc586c0b60a04823c0e930b227af2828d8.tar.bz2
lua-de79e7fc586c0b60a04823c0e930b227af2828d8.zip
back to "lua_upvalue"... (seems better choice)
-rw-r--r--lapi.c11
-rw-r--r--lbuiltin.c3
-rw-r--r--ldo.c18
-rw-r--r--liolib.c21
-rw-r--r--lua.h3
5 files changed, 27 insertions, 29 deletions
diff --git a/lapi.c b/lapi.c
index 3899bb86..464ef60a 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.13 1997/12/11 14:48:46 roberto Exp roberto $ 2** $Id: lapi.c,v 1.14 1997/12/15 16:17:20 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*/
@@ -124,6 +124,15 @@ lua_Object lua_lua2C (int number)
124} 124}
125 125
126 126
127lua_Object lua_upvalue (int n)
128{
129 TObject *f = L->stack.stack+L->Cstack.lua2C-1;
130 if (ttype(f) != LUA_T_CLMARK || n <= 0 || n > clvalue(f)->nelems)
131 return LUA_NOOBJECT;
132 return put_luaObject(&clvalue(f)->consts[n]);
133}
134
135
127int lua_callfunction (lua_Object function) 136int lua_callfunction (lua_Object function)
128{ 137{
129 if (function == LUA_NOOBJECT) 138 if (function == LUA_NOOBJECT)
diff --git a/lbuiltin.c b/lbuiltin.c
index fa83e58a..da2c915c 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.17 1997/12/15 16:17:20 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.18 1997/12/17 20:48:58 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -427,6 +427,7 @@ static void testC (void)
427 case 'r': { int n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; } 427 case 'r': { int n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; }
428 case 'u': lua_unref(locks[getnum(s)]); break; 428 case 'u': lua_unref(locks[getnum(s)]); break;
429 case 'p': { int n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; } 429 case 'p': { int n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; }
430 case 'U': { int n = getnum(s); reg[n] = lua_upvalue(getnum(s)); break; }
430 case '=': lua_setglobal(getname(s)); break; 431 case '=': lua_setglobal(getname(s)); break;
431 case 's': lua_pushstring(getname(s)); break; 432 case 's': lua_pushstring(getname(s)); break;
432 case 'o': lua_pushobject(reg[getnum(s)]); break; 433 case 'o': lua_pushobject(reg[getnum(s)]); break;
diff --git a/ldo.c b/ldo.c
index 01af05c4..8ab4854f 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.15 1997/12/15 16:17:20 roberto Exp roberto $ 2** $Id: ldo.c,v 1.16 1997/12/17 20:57:20 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -140,22 +140,12 @@ void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn)
140** Cstack.num is the number of arguments; Cstack.lua2C points to the 140** Cstack.num is the number of arguments; Cstack.lua2C points to the
141** first argument. Returns an index to the first result from C. 141** first argument. Returns an index to the first result from C.
142*/ 142*/
143static StkId callC (struct Closure *cl, lua_CFunction f, StkId base) 143static StkId callC (lua_CFunction f, StkId base)
144{ 144{
145 struct C_Lua_Stack *CS = &L->Cstack; 145 struct C_Lua_Stack *CS = &L->Cstack;
146 struct C_Lua_Stack oldCLS = *CS; 146 struct C_Lua_Stack oldCLS = *CS;
147 StkId firstResult; 147 StkId firstResult;
148 int numarg = (L->stack.top-L->stack.stack) - base; 148 int numarg = (L->stack.top-L->stack.stack) - base;
149 if (cl) { /* are there upvalues? */
150 int i;
151 luaD_checkstack(cl->nelems);
152 for (i=1; i<=numarg; i++) /* open space */
153 *(L->stack.top+cl->nelems-i) = *(L->stack.top-i);
154 /* copy upvalues to stack */
155 memcpy(L->stack.top-numarg, cl->consts+1, cl->nelems*sizeof(TObject));
156 L->stack.top += cl->nelems;
157 numarg += cl->nelems;
158 }
159 CS->num = numarg; 149 CS->num = numarg;
160 CS->lua2C = base; 150 CS->lua2C = base;
161 CS->base = base+numarg; /* == top-stack */ 151 CS->base = base+numarg; /* == top-stack */
@@ -192,7 +182,7 @@ void luaD_call (StkId base, int nResults)
192 switch (ttype(func)) { 182 switch (ttype(func)) {
193 case LUA_T_CPROTO: 183 case LUA_T_CPROTO:
194 ttype(func) = LUA_T_CMARK; 184 ttype(func) = LUA_T_CMARK;
195 firstResult = callC(NULL, fvalue(func), base); 185 firstResult = callC(fvalue(func), base);
196 break; 186 break;
197 case LUA_T_PROTO: 187 case LUA_T_PROTO:
198 ttype(func) = LUA_T_PMARK; 188 ttype(func) = LUA_T_PMARK;
@@ -203,7 +193,7 @@ void luaD_call (StkId base, int nResults)
203 TObject *proto = &(c->consts[0]); 193 TObject *proto = &(c->consts[0]);
204 ttype(func) = LUA_T_CLMARK; 194 ttype(func) = LUA_T_CLMARK;
205 firstResult = (ttype(proto) == LUA_T_CPROTO) ? 195 firstResult = (ttype(proto) == LUA_T_CPROTO) ?
206 callC(c, fvalue(proto), base) : 196 callC(fvalue(proto), base) :
207 luaV_execute(c, tfvalue(proto), base); 197 luaV_execute(c, tfvalue(proto), base);
208 break; 198 break;
209 } 199 }
diff --git a/liolib.c b/liolib.c
index 46c4e87c..7a61560f 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.9 1997/12/09 13:50:08 roberto Exp roberto $ 2** $Id: liolib.c,v 1.10 1997/12/17 20:48:58 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -39,9 +39,6 @@
39#define FOUTPUT "_OUTPUT" 39#define FOUTPUT "_OUTPUT"
40 40
41 41
42#define FIRSTARG 3 /* 1st and 2nd are upvalues */
43
44
45#ifdef POPEN 42#ifdef POPEN
46FILE *popen(); 43FILE *popen();
47int pclose(); 44int pclose();
@@ -53,7 +50,7 @@ int pclose();
53 50
54static int gettag (int i) 51static int gettag (int i)
55{ 52{
56 return lua_getnumber(lua_getparam(i)); 53 return lua_getnumber(lua_upvalue(i));
57} 54}
58 55
59 56
@@ -128,7 +125,7 @@ static void setreturn (FILE *f, char *name)
128static void io_readfrom (void) 125static void io_readfrom (void)
129{ 126{
130 FILE *current; 127 FILE *current;
131 lua_Object f = lua_getparam(FIRSTARG); 128 lua_Object f = lua_getparam(1);
132 if (f == LUA_NOOBJECT) { 129 if (f == LUA_NOOBJECT) {
133 closefile(FINPUT); 130 closefile(FINPUT);
134 current = stdin; 131 current = stdin;
@@ -136,7 +133,7 @@ static void io_readfrom (void)
136 else if (lua_tag(f) == gettag(IOTAG)) 133 else if (lua_tag(f) == gettag(IOTAG))
137 current = lua_getuserdata(f); 134 current = lua_getuserdata(f);
138 else { 135 else {
139 char *s = luaL_check_string(FIRSTARG); 136 char *s = luaL_check_string(1);
140 current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); 137 current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
141 if (current == NULL) { 138 if (current == NULL) {
142 pushresult(0); 139 pushresult(0);
@@ -150,7 +147,7 @@ static void io_readfrom (void)
150static void io_writeto (void) 147static void io_writeto (void)
151{ 148{
152 FILE *current; 149 FILE *current;
153 lua_Object f = lua_getparam(FIRSTARG); 150 lua_Object f = lua_getparam(1);
154 if (f == LUA_NOOBJECT) { 151 if (f == LUA_NOOBJECT) {
155 closefile(FOUTPUT); 152 closefile(FOUTPUT);
156 current = stdout; 153 current = stdout;
@@ -158,7 +155,7 @@ static void io_writeto (void)
158 else if (lua_tag(f) == gettag(IOTAG)) 155 else if (lua_tag(f) == gettag(IOTAG))
159 current = lua_getuserdata(f); 156 current = lua_getuserdata(f);
160 else { 157 else {
161 char *s = luaL_check_string(FIRSTARG); 158 char *s = luaL_check_string(1);
162 current = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); 159 current = (*s == '|') ? popen(s+1,"w") : fopen(s,"w");
163 if (current == NULL) { 160 if (current == NULL) {
164 pushresult(0); 161 pushresult(0);
@@ -171,7 +168,7 @@ static void io_writeto (void)
171 168
172static void io_appendto (void) 169static void io_appendto (void)
173{ 170{
174 char *s = luaL_check_string(FIRSTARG); 171 char *s = luaL_check_string(1);
175 FILE *fp = fopen (s, "a"); 172 FILE *fp = fopen (s, "a");
176 if (fp != NULL) 173 if (fp != NULL)
177 setreturn(fp, FOUTPUT); 174 setreturn(fp, FOUTPUT);
@@ -184,7 +181,7 @@ static void io_appendto (void)
184 181
185static void io_read (void) 182static void io_read (void)
186{ 183{
187 int arg = FIRSTARG; 184 int arg = 1;
188 FILE *f = getfileparam(FINPUT, &arg); 185 FILE *f = getfileparam(FINPUT, &arg);
189 char *buff; 186 char *buff;
190 char *p = luaL_opt_string(arg, "[^\n]*{\n}"); 187 char *p = luaL_opt_string(arg, "[^\n]*{\n}");
@@ -236,7 +233,7 @@ static void io_read (void)
236 233
237static void io_write (void) 234static void io_write (void)
238{ 235{
239 int arg = FIRSTARG; 236 int arg = 1;
240 FILE *f = getfileparam(FOUTPUT, &arg); 237 FILE *f = getfileparam(FOUTPUT, &arg);
241 int status = 1; 238 int status = 1;
242 char *s; 239 char *s;
diff --git a/lua.h b/lua.h
index 5dae0dbc..bb9b65dd 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.10 1997/12/11 17:21:11 roberto Exp roberto $ 2** $Id: lua.h,v 1.11 1997/12/15 17:47:55 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: lua@tecgraf.puc-rio.br 5** e-mail: lua@tecgraf.puc-rio.br
@@ -77,6 +77,7 @@ void lua_beginblock (void);
77void lua_endblock (void); 77void lua_endblock (void);
78 78
79lua_Object lua_lua2C (int number); 79lua_Object lua_lua2C (int number);
80lua_Object lua_upvalue (int n);
80#define lua_getparam(_) lua_lua2C(_) 81#define lua_getparam(_) lua_lua2C(_)
81#define lua_getresult(_) lua_lua2C(_) 82#define lua_getresult(_) lua_lua2C(_)
82 83