From de79e7fc586c0b60a04823c0e930b227af2828d8 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 18 Dec 1997 16:32:39 -0200 Subject: back to "lua_upvalue"... (seems better choice) --- liolib.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'liolib.c') diff --git a/liolib.c b/liolib.c index 46c4e87c..7a61560f 100644 --- a/liolib.c +++ b/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; -- cgit v1.2.3-55-g6feb