diff options
Diffstat (limited to 'liolib.c')
| -rw-r--r-- | liolib.c | 18 |
1 files changed, 9 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.74 2000/08/29 20:43:28 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.75 2000/08/31 13:30:10 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 | */ |
| @@ -150,14 +150,14 @@ static int closefile (lua_State *L, IOCtrl *ctrl, FILE *f) { | |||
| 150 | 150 | ||
| 151 | static int io_close (lua_State *L) { | 151 | static int io_close (lua_State *L) { |
| 152 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); | 152 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); |
| 153 | lua_settop(L, -1); /* remove upvalue */ | 153 | lua_pop(L, 1); /* remove upvalue */ |
| 154 | return pushresult(L, closefile(L, ctrl, getnonullfile(L, ctrl, 1))); | 154 | return pushresult(L, closefile(L, ctrl, getnonullfile(L, ctrl, 1))); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | 157 | ||
| 158 | static int file_collect (lua_State *L) { | 158 | static int file_collect (lua_State *L) { |
| 159 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); | 159 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); |
| 160 | lua_settop(L, -1); /* remove upvalue */ | 160 | lua_pop(L, 1); /* remove upvalue */ |
| 161 | if (ctrl == (IOCtrl *)lua_touserdata(L, 1)) { | 161 | if (ctrl == (IOCtrl *)lua_touserdata(L, 1)) { |
| 162 | /* collecting `ctrl' itself */ | 162 | /* collecting `ctrl' itself */ |
| 163 | lua_unref(L, ctrl->ref[INFILE]); | 163 | lua_unref(L, ctrl->ref[INFILE]); |
| @@ -176,7 +176,7 @@ static int file_collect (lua_State *L) { | |||
| 176 | static int io_open (lua_State *L) { | 176 | static int io_open (lua_State *L) { |
| 177 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); | 177 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); |
| 178 | FILE *f; | 178 | FILE *f; |
| 179 | lua_settop(L, -1); /* remove upvalue */ | 179 | lua_pop(L, 1); /* remove upvalue */ |
| 180 | f = fopen(luaL_check_string(L, 1), luaL_check_string(L, 2)); | 180 | f = fopen(luaL_check_string(L, 1), luaL_check_string(L, 2)); |
| 181 | if (f) { | 181 | if (f) { |
| 182 | lua_pushusertag(L, f, ctrl->iotag); | 182 | lua_pushusertag(L, f, ctrl->iotag); |
| @@ -191,7 +191,7 @@ static int io_open (lua_State *L) { | |||
| 191 | static int io_fromto (lua_State *L, int inout, const char *mode) { | 191 | static int io_fromto (lua_State *L, int inout, const char *mode) { |
| 192 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); | 192 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); |
| 193 | FILE *current; | 193 | FILE *current; |
| 194 | lua_settop(L, -1); /* remove upvalue */ | 194 | lua_pop(L, 1); /* remove upvalue */ |
| 195 | if (lua_isnull(L, 1)) { | 195 | if (lua_isnull(L, 1)) { |
| 196 | closefile(L, ctrl, getfilebyref(L, ctrl, inout)); | 196 | closefile(L, ctrl, getfilebyref(L, ctrl, inout)); |
| 197 | current = (inout == 0) ? stdin : stdout; | 197 | current = (inout == 0) ? stdin : stdout; |
| @@ -219,7 +219,7 @@ static int io_writeto (lua_State *L) { | |||
| 219 | static int io_appendto (lua_State *L) { | 219 | static int io_appendto (lua_State *L) { |
| 220 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); | 220 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); |
| 221 | FILE *current; | 221 | FILE *current; |
| 222 | lua_settop(L, -1); /* remove upvalue */ | 222 | lua_pop(L, 1); /* remove upvalue */ |
| 223 | current = fopen(luaL_check_string(L, 1), "a"); | 223 | current = fopen(luaL_check_string(L, 1), "a"); |
| 224 | return setreturn(L, ctrl, current, OUTFILE); | 224 | return setreturn(L, ctrl, current, OUTFILE); |
| 225 | } | 225 | } |
| @@ -366,7 +366,7 @@ static int io_read (lua_State *L) { | |||
| 366 | int n; | 366 | int n; |
| 367 | if (f) firstarg++; | 367 | if (f) firstarg++; |
| 368 | else f = getfilebyref(L, ctrl, INFILE); /* get _INPUT */ | 368 | else f = getfilebyref(L, ctrl, INFILE); /* get _INPUT */ |
| 369 | lua_settop(L, -1); | 369 | lua_pop(L, 1); |
| 370 | if (firstarg > lastarg) { /* no arguments? */ | 370 | if (firstarg > lastarg) { /* no arguments? */ |
| 371 | lua_settop(L, 0); /* erase upvalue and other eventual garbage */ | 371 | lua_settop(L, 0); /* erase upvalue and other eventual garbage */ |
| 372 | firstarg = lastarg = 1; /* correct indices */ | 372 | firstarg = lastarg = 1; /* correct indices */ |
| @@ -447,7 +447,7 @@ static int io_seek (lua_State *L) { | |||
| 447 | FILE *f; | 447 | FILE *f; |
| 448 | int op; | 448 | int op; |
| 449 | long offset; | 449 | long offset; |
| 450 | lua_settop(L, -1); /* remove upvalue */ | 450 | lua_pop(L, 1); /* remove upvalue */ |
| 451 | f = getnonullfile(L, ctrl, 1); | 451 | f = getnonullfile(L, ctrl, 1); |
| 452 | op = luaL_findstring(luaL_opt_string(L, 2, "cur"), modenames); | 452 | op = luaL_findstring(luaL_opt_string(L, 2, "cur"), modenames); |
| 453 | offset = luaL_opt_long(L, 3, 0); | 453 | offset = luaL_opt_long(L, 3, 0); |
| @@ -465,7 +465,7 @@ static int io_seek (lua_State *L) { | |||
| 465 | static int io_flush (lua_State *L) { | 465 | static int io_flush (lua_State *L) { |
| 466 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); | 466 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); |
| 467 | FILE *f; | 467 | FILE *f; |
| 468 | lua_settop(L, -1); /* remove upvalue */ | 468 | lua_pop(L, 1); /* remove upvalue */ |
| 469 | f = gethandle(L, ctrl, 1); | 469 | f = gethandle(L, ctrl, 1); |
| 470 | luaL_arg_check(L, f || lua_isnull(L, 1), 1, "invalid file handle"); | 470 | luaL_arg_check(L, f || lua_isnull(L, 1), 1, "invalid file handle"); |
| 471 | return pushresult(L, fflush(f) == 0); | 471 | return pushresult(L, fflush(f) == 0); |
