diff options
Diffstat (limited to 'liolib.c')
| -rw-r--r-- | liolib.c | 24 |
1 files changed, 12 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.45 2003/07/09 12:08:43 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.46 2003/08/25 19:49:47 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 | */ |
| @@ -76,7 +76,7 @@ static int pushresult (lua_State *L, int i, const char *filename) { | |||
| 76 | lua_pushfstring(L, "%s: %s", filename, strerror(errno)); | 76 | lua_pushfstring(L, "%s: %s", filename, strerror(errno)); |
| 77 | else | 77 | else |
| 78 | lua_pushfstring(L, "%s", strerror(errno)); | 78 | lua_pushfstring(L, "%s", strerror(errno)); |
| 79 | lua_pushnumber(L, errno); | 79 | lua_pushinteger(L, errno); |
| 80 | return 3; | 80 | return 3; |
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| @@ -346,7 +346,7 @@ static int g_read (lua_State *L, FILE *f, int first) { | |||
| 346 | success = 1; | 346 | success = 1; |
| 347 | for (n = first; nargs-- && success; n++) { | 347 | for (n = first; nargs-- && success; n++) { |
| 348 | if (lua_type(L, n) == LUA_TNUMBER) { | 348 | if (lua_type(L, n) == LUA_TNUMBER) { |
| 349 | size_t l = (size_t)lua_tonumber(L, n); | 349 | size_t l = (size_t)lua_tointeger(L, n); |
| 350 | success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); | 350 | success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); |
| 351 | } | 351 | } |
| 352 | else { | 352 | else { |
| @@ -441,13 +441,13 @@ static int f_seek (lua_State *L) { | |||
| 441 | static const char *const modenames[] = {"set", "cur", "end", NULL}; | 441 | static const char *const modenames[] = {"set", "cur", "end", NULL}; |
| 442 | FILE *f = tofile(L, 1); | 442 | FILE *f = tofile(L, 1); |
| 443 | int op = luaL_findstring(luaL_optstring(L, 2, "cur"), modenames); | 443 | int op = luaL_findstring(luaL_optstring(L, 2, "cur"), modenames); |
| 444 | long offset = luaL_optlong(L, 3, 0); | 444 | lua_Integer offset = luaL_optinteger(L, 3, 0); |
| 445 | luaL_argcheck(L, op != -1, 2, "invalid mode"); | 445 | luaL_argcheck(L, op != -1, 2, "invalid mode"); |
| 446 | op = fseek(f, offset, mode[op]); | 446 | op = fseek(f, offset, mode[op]); |
| 447 | if (op) | 447 | if (op) |
| 448 | return pushresult(L, 0, NULL); /* error */ | 448 | return pushresult(L, 0, NULL); /* error */ |
| 449 | else { | 449 | else { |
| 450 | lua_pushnumber(L, ftell(f)); | 450 | lua_pushinteger(L, ftell(f)); |
| 451 | return 1; | 451 | return 1; |
| 452 | } | 452 | } |
| 453 | } | 453 | } |
| @@ -528,7 +528,7 @@ static void createmeta (lua_State *L) { | |||
| 528 | */ | 528 | */ |
| 529 | 529 | ||
| 530 | static int io_execute (lua_State *L) { | 530 | static int io_execute (lua_State *L) { |
| 531 | lua_pushnumber(L, system(luaL_checkstring(L, 1))); | 531 | lua_pushinteger(L, system(luaL_checkstring(L, 1))); |
| 532 | return 1; | 532 | return 1; |
| 533 | } | 533 | } |
| 534 | 534 | ||
| @@ -582,7 +582,7 @@ static int io_clock (lua_State *L) { | |||
| 582 | 582 | ||
| 583 | static void setfield (lua_State *L, const char *key, int value) { | 583 | static void setfield (lua_State *L, const char *key, int value) { |
| 584 | lua_pushstring(L, key); | 584 | lua_pushstring(L, key); |
| 585 | lua_pushnumber(L, value); | 585 | lua_pushinteger(L, value); |
| 586 | lua_rawset(L, -3); | 586 | lua_rawset(L, -3); |
| 587 | } | 587 | } |
| 588 | 588 | ||
| @@ -607,9 +607,9 @@ static int getfield (lua_State *L, const char *key, int d) { | |||
| 607 | lua_pushstring(L, key); | 607 | lua_pushstring(L, key); |
| 608 | lua_gettable(L, -2); | 608 | lua_gettable(L, -2); |
| 609 | if (lua_isnumber(L, -1)) | 609 | if (lua_isnumber(L, -1)) |
| 610 | res = (int)(lua_tonumber(L, -1)); | 610 | res = (int)lua_tointeger(L, -1); |
| 611 | else { | 611 | else { |
| 612 | if (d == -2) | 612 | if (d < 0) |
| 613 | return luaL_error(L, "field `%s' missing in date table", key); | 613 | return luaL_error(L, "field `%s' missing in date table", key); |
| 614 | res = d; | 614 | res = d; |
| 615 | } | 615 | } |
| @@ -665,9 +665,9 @@ static int io_time (lua_State *L) { | |||
| 665 | ts.tm_sec = getfield(L, "sec", 0); | 665 | ts.tm_sec = getfield(L, "sec", 0); |
| 666 | ts.tm_min = getfield(L, "min", 0); | 666 | ts.tm_min = getfield(L, "min", 0); |
| 667 | ts.tm_hour = getfield(L, "hour", 12); | 667 | ts.tm_hour = getfield(L, "hour", 12); |
| 668 | ts.tm_mday = getfield(L, "day", -2); | 668 | ts.tm_mday = getfield(L, "day", -1); |
| 669 | ts.tm_mon = getfield(L, "month", -2) - 1; | 669 | ts.tm_mon = getfield(L, "month", -1) - 1; |
| 670 | ts.tm_year = getfield(L, "year", -2) - 1900; | 670 | ts.tm_year = getfield(L, "year", -1) - 1900; |
| 671 | ts.tm_isdst = getboolfield(L, "isdst"); | 671 | ts.tm_isdst = getboolfield(L, "isdst"); |
| 672 | t = mktime(&ts); | 672 | t = mktime(&ts); |
| 673 | if (t == (time_t)(-1)) | 673 | if (t == (time_t)(-1)) |
