mirror of
https://github.com/lua/lua
synced 2024-11-22 21:01:26 +03:00
back to "lua_upvalue"... (seems better choice)
This commit is contained in:
parent
8b5b42563c
commit
de79e7fc58
11
lapi.c
11
lapi.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lapi.c,v 1.13 1997/12/11 14:48:46 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 1.14 1997/12/15 16:17:20 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -124,6 +124,15 @@ lua_Object lua_lua2C (int number)
|
||||
}
|
||||
|
||||
|
||||
lua_Object lua_upvalue (int n)
|
||||
{
|
||||
TObject *f = L->stack.stack+L->Cstack.lua2C-1;
|
||||
if (ttype(f) != LUA_T_CLMARK || n <= 0 || n > clvalue(f)->nelems)
|
||||
return LUA_NOOBJECT;
|
||||
return put_luaObject(&clvalue(f)->consts[n]);
|
||||
}
|
||||
|
||||
|
||||
int lua_callfunction (lua_Object function)
|
||||
{
|
||||
if (function == LUA_NOOBJECT)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbuiltin.c,v 1.17 1997/12/15 16:17:20 roberto Exp roberto $
|
||||
** $Id: lbuiltin.c,v 1.18 1997/12/17 20:48:58 roberto Exp roberto $
|
||||
** Built-in functions
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -427,6 +427,7 @@ static void testC (void)
|
||||
case 'r': { int n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; }
|
||||
case 'u': lua_unref(locks[getnum(s)]); break;
|
||||
case 'p': { int n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; }
|
||||
case 'U': { int n = getnum(s); reg[n] = lua_upvalue(getnum(s)); break; }
|
||||
case '=': lua_setglobal(getname(s)); break;
|
||||
case 's': lua_pushstring(getname(s)); break;
|
||||
case 'o': lua_pushobject(reg[getnum(s)]); break;
|
||||
|
18
ldo.c
18
ldo.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldo.c,v 1.15 1997/12/15 16:17:20 roberto Exp roberto $
|
||||
** $Id: ldo.c,v 1.16 1997/12/17 20:57:20 roberto Exp roberto $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -140,22 +140,12 @@ void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn)
|
||||
** Cstack.num is the number of arguments; Cstack.lua2C points to the
|
||||
** first argument. Returns an index to the first result from C.
|
||||
*/
|
||||
static StkId callC (struct Closure *cl, lua_CFunction f, StkId base)
|
||||
static StkId callC (lua_CFunction f, StkId base)
|
||||
{
|
||||
struct C_Lua_Stack *CS = &L->Cstack;
|
||||
struct C_Lua_Stack oldCLS = *CS;
|
||||
StkId firstResult;
|
||||
int numarg = (L->stack.top-L->stack.stack) - base;
|
||||
if (cl) { /* are there upvalues? */
|
||||
int i;
|
||||
luaD_checkstack(cl->nelems);
|
||||
for (i=1; i<=numarg; i++) /* open space */
|
||||
*(L->stack.top+cl->nelems-i) = *(L->stack.top-i);
|
||||
/* copy upvalues to stack */
|
||||
memcpy(L->stack.top-numarg, cl->consts+1, cl->nelems*sizeof(TObject));
|
||||
L->stack.top += cl->nelems;
|
||||
numarg += cl->nelems;
|
||||
}
|
||||
CS->num = numarg;
|
||||
CS->lua2C = base;
|
||||
CS->base = base+numarg; /* == top-stack */
|
||||
@ -192,7 +182,7 @@ void luaD_call (StkId base, int nResults)
|
||||
switch (ttype(func)) {
|
||||
case LUA_T_CPROTO:
|
||||
ttype(func) = LUA_T_CMARK;
|
||||
firstResult = callC(NULL, fvalue(func), base);
|
||||
firstResult = callC(fvalue(func), base);
|
||||
break;
|
||||
case LUA_T_PROTO:
|
||||
ttype(func) = LUA_T_PMARK;
|
||||
@ -203,7 +193,7 @@ void luaD_call (StkId base, int nResults)
|
||||
TObject *proto = &(c->consts[0]);
|
||||
ttype(func) = LUA_T_CLMARK;
|
||||
firstResult = (ttype(proto) == LUA_T_CPROTO) ?
|
||||
callC(c, fvalue(proto), base) :
|
||||
callC(fvalue(proto), base) :
|
||||
luaV_execute(c, tfvalue(proto), base);
|
||||
break;
|
||||
}
|
||||
|
21
liolib.c
21
liolib.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: liolib.c,v 1.9 1997/12/09 13:50:08 roberto Exp roberto $
|
||||
** $Id: liolib.c,v 1.10 1997/12/17 20:48:58 roberto Exp roberto $
|
||||
** Standard I/O (and system) library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -39,9 +39,6 @@
|
||||
#define FOUTPUT "_OUTPUT"
|
||||
|
||||
|
||||
#define FIRSTARG 3 /* 1st and 2nd are upvalues */
|
||||
|
||||
|
||||
#ifdef POPEN
|
||||
FILE *popen();
|
||||
int pclose();
|
||||
@ -53,7 +50,7 @@ int pclose();
|
||||
|
||||
static int gettag (int i)
|
||||
{
|
||||
return lua_getnumber(lua_getparam(i));
|
||||
return lua_getnumber(lua_upvalue(i));
|
||||
}
|
||||
|
||||
|
||||
@ -128,7 +125,7 @@ static void setreturn (FILE *f, char *name)
|
||||
static void io_readfrom (void)
|
||||
{
|
||||
FILE *current;
|
||||
lua_Object f = lua_getparam(FIRSTARG);
|
||||
lua_Object f = lua_getparam(1);
|
||||
if (f == LUA_NOOBJECT) {
|
||||
closefile(FINPUT);
|
||||
current = stdin;
|
||||
@ -136,7 +133,7 @@ static void io_readfrom (void)
|
||||
else if (lua_tag(f) == gettag(IOTAG))
|
||||
current = lua_getuserdata(f);
|
||||
else {
|
||||
char *s = luaL_check_string(FIRSTARG);
|
||||
char *s = luaL_check_string(1);
|
||||
current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
|
||||
if (current == NULL) {
|
||||
pushresult(0);
|
||||
@ -150,7 +147,7 @@ static void io_readfrom (void)
|
||||
static void io_writeto (void)
|
||||
{
|
||||
FILE *current;
|
||||
lua_Object f = lua_getparam(FIRSTARG);
|
||||
lua_Object f = lua_getparam(1);
|
||||
if (f == LUA_NOOBJECT) {
|
||||
closefile(FOUTPUT);
|
||||
current = stdout;
|
||||
@ -158,7 +155,7 @@ static void io_writeto (void)
|
||||
else if (lua_tag(f) == gettag(IOTAG))
|
||||
current = lua_getuserdata(f);
|
||||
else {
|
||||
char *s = luaL_check_string(FIRSTARG);
|
||||
char *s = luaL_check_string(1);
|
||||
current = (*s == '|') ? popen(s+1,"w") : fopen(s,"w");
|
||||
if (current == NULL) {
|
||||
pushresult(0);
|
||||
@ -171,7 +168,7 @@ static void io_writeto (void)
|
||||
|
||||
static void io_appendto (void)
|
||||
{
|
||||
char *s = luaL_check_string(FIRSTARG);
|
||||
char *s = luaL_check_string(1);
|
||||
FILE *fp = fopen (s, "a");
|
||||
if (fp != NULL)
|
||||
setreturn(fp, FOUTPUT);
|
||||
@ -184,7 +181,7 @@ static void io_appendto (void)
|
||||
|
||||
static void io_read (void)
|
||||
{
|
||||
int arg = FIRSTARG;
|
||||
int arg = 1;
|
||||
FILE *f = getfileparam(FINPUT, &arg);
|
||||
char *buff;
|
||||
char *p = luaL_opt_string(arg, "[^\n]*{\n}");
|
||||
@ -236,7 +233,7 @@ static void io_read (void)
|
||||
|
||||
static void io_write (void)
|
||||
{
|
||||
int arg = FIRSTARG;
|
||||
int arg = 1;
|
||||
FILE *f = getfileparam(FOUTPUT, &arg);
|
||||
int status = 1;
|
||||
char *s;
|
||||
|
3
lua.h
3
lua.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lua.h,v 1.10 1997/12/11 17:21:11 roberto Exp roberto $
|
||||
** $Id: lua.h,v 1.11 1997/12/15 17:47:55 roberto Exp roberto $
|
||||
** Lua - An Extensible Extension Language
|
||||
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
||||
** e-mail: lua@tecgraf.puc-rio.br
|
||||
@ -77,6 +77,7 @@ void lua_beginblock (void);
|
||||
void lua_endblock (void);
|
||||
|
||||
lua_Object lua_lua2C (int number);
|
||||
lua_Object lua_upvalue (int n);
|
||||
#define lua_getparam(_) lua_lua2C(_)
|
||||
#define lua_getresult(_) lua_lua2C(_)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user