diff options
Diffstat (limited to '')
| -rw-r--r-- | liolib.c | 21 |
1 files changed, 11 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.94 2000/12/18 13:42:19 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.95 2000/12/22 16:57:13 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 | */ |
| @@ -318,6 +318,7 @@ static int io_read (lua_State *L) { | |||
| 318 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); | 318 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); |
| 319 | int lastarg = lua_gettop(L) - 1; | 319 | int lastarg = lua_gettop(L) - 1; |
| 320 | int firstarg = 1; | 320 | int firstarg = 1; |
| 321 | int success; | ||
| 321 | FILE *f = gethandle(L, ctrl, firstarg); | 322 | FILE *f = gethandle(L, ctrl, firstarg); |
| 322 | int n; | 323 | int n; |
| 323 | if (f) firstarg++; | 324 | if (f) firstarg++; |
| @@ -330,8 +331,8 @@ static int io_read (lua_State *L) { | |||
| 330 | } | 331 | } |
| 331 | else /* ensure stack space for all results and for auxlib's buffer */ | 332 | else /* ensure stack space for all results and for auxlib's buffer */ |
| 332 | luaL_checkstack(L, lastarg-firstarg+1+LUA_MINSTACK, "too many arguments"); | 333 | luaL_checkstack(L, lastarg-firstarg+1+LUA_MINSTACK, "too many arguments"); |
| 333 | for (n = firstarg; n<=lastarg; n++) { | 334 | success = 1; |
| 334 | int success; | 335 | for (n = firstarg; n<=lastarg && success; n++) { |
| 335 | if (lua_isnumber(L, n)) | 336 | if (lua_isnumber(L, n)) |
| 336 | success = read_chars(L, f, (size_t)lua_tonumber(L, n)); | 337 | success = read_chars(L, f, (size_t)lua_tonumber(L, n)); |
| 337 | else { | 338 | else { |
| @@ -343,8 +344,8 @@ static int io_read (lua_State *L) { | |||
| 343 | else { | 344 | else { |
| 344 | switch (p[1]) { | 345 | switch (p[1]) { |
| 345 | case 'n': /* number */ | 346 | case 'n': /* number */ |
| 346 | if (!read_number(L, f)) goto endloop; /* read fails */ | 347 | success = read_number(L, f); |
| 347 | continue; /* number is already pushed; avoid the "pushstring" */ | 348 | break; |
| 348 | case 'l': /* line */ | 349 | case 'l': /* line */ |
| 349 | success = read_line(L, f); | 350 | success = read_line(L, f); |
| 350 | break; | 351 | break; |
| @@ -361,11 +362,11 @@ static int io_read (lua_State *L) { | |||
| 361 | } | 362 | } |
| 362 | } | 363 | } |
| 363 | } | 364 | } |
| 364 | if (!success) { | 365 | } |
| 365 | lua_pop(L, 1); /* remove last result */ | 366 | if (!success) { |
| 366 | break; /* read fails */ | 367 | lua_pop(L, 1); /* remove last result */ |
| 367 | } | 368 | lua_pushnil(L); /* push nil instead */ |
| 368 | } endloop: | 369 | } |
| 369 | return n - firstarg; | 370 | return n - firstarg; |
| 370 | } | 371 | } |
| 371 | 372 | ||
