diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-18 16:32:39 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-18 16:32:39 -0200 |
| commit | de79e7fc586c0b60a04823c0e930b227af2828d8 (patch) | |
| tree | e48cd57eba16106100fb18e2bd2c1ab19f841347 /liolib.c | |
| parent | 8b5b42563c317f83318a0386551f0f0252e387dc (diff) | |
| download | lua-de79e7fc586c0b60a04823c0e930b227af2828d8.tar.gz lua-de79e7fc586c0b60a04823c0e930b227af2828d8.tar.bz2 lua-de79e7fc586c0b60a04823c0e930b227af2828d8.zip | |
back to "lua_upvalue"... (seems better choice)
Diffstat (limited to 'liolib.c')
| -rw-r--r-- | liolib.c | 21 |
1 files changed, 9 insertions, 12 deletions
| @@ -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 |
| 46 | FILE *popen(); | 43 | FILE *popen(); |
| 47 | int pclose(); | 44 | int pclose(); |
| @@ -53,7 +50,7 @@ int pclose(); | |||
| 53 | 50 | ||
| 54 | static int gettag (int i) | 51 | static 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) | |||
| 128 | static void io_readfrom (void) | 125 | static 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) | |||
| 150 | static void io_writeto (void) | 147 | static 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 | ||
| 172 | static void io_appendto (void) | 169 | static 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 | ||
| 185 | static void io_read (void) | 182 | static 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 | ||
| 237 | static void io_write (void) | 234 | static 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; |
