diff options
-rw-r--r-- | liolib.c | 29 |
1 files changed, 11 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.93 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.94 2000/12/18 13:42:19 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 | */ |
@@ -506,19 +506,6 @@ static int getfield (lua_State *L, const char *key, int d) { | |||
506 | } | 506 | } |
507 | 507 | ||
508 | 508 | ||
509 | static void tm2table (lua_State *L, struct tm *stm) { | ||
510 | setfield(L, "sec", stm->tm_sec); | ||
511 | setfield(L, "min", stm->tm_min); | ||
512 | setfield(L, "hour", stm->tm_hour); | ||
513 | setfield(L, "day", stm->tm_mday); | ||
514 | setfield(L, "month", stm->tm_mon+1); | ||
515 | setfield(L, "year", stm->tm_year+1900); | ||
516 | setfield(L, "wday", stm->tm_wday+1); | ||
517 | setfield(L, "yday", stm->tm_yday+1); | ||
518 | setfield(L, "isdst", stm->tm_isdst); | ||
519 | } | ||
520 | |||
521 | |||
522 | static int io_date (lua_State *L) { | 509 | static int io_date (lua_State *L) { |
523 | const char *s = luaL_opt_string(L, 1, "%c"); | 510 | const char *s = luaL_opt_string(L, 1, "%c"); |
524 | time_t t = (time_t)luaL_opt_number(L, 2, -1); | 511 | time_t t = (time_t)luaL_opt_number(L, 2, -1); |
@@ -535,7 +522,15 @@ static int io_date (lua_State *L) { | |||
535 | lua_pushnil(L); | 522 | lua_pushnil(L); |
536 | else if (strcmp(s, "*t") == 0) { | 523 | else if (strcmp(s, "*t") == 0) { |
537 | lua_newtable(L); | 524 | lua_newtable(L); |
538 | tm2table(L, stm); | 525 | setfield(L, "sec", stm->tm_sec); |
526 | setfield(L, "min", stm->tm_min); | ||
527 | setfield(L, "hour", stm->tm_hour); | ||
528 | setfield(L, "day", stm->tm_mday); | ||
529 | setfield(L, "month", stm->tm_mon+1); | ||
530 | setfield(L, "year", stm->tm_year+1900); | ||
531 | setfield(L, "wday", stm->tm_wday+1); | ||
532 | setfield(L, "yday", stm->tm_yday+1); | ||
533 | setfield(L, "isdst", stm->tm_isdst); | ||
539 | } | 534 | } |
540 | else { | 535 | else { |
541 | char b[256]; | 536 | char b[256]; |
@@ -566,10 +561,8 @@ static int io_time (lua_State *L) { | |||
566 | t = mktime(&ts); | 561 | t = mktime(&ts); |
567 | if (t == (time_t)-1) | 562 | if (t == (time_t)-1) |
568 | lua_pushnil(L); | 563 | lua_pushnil(L); |
569 | else { | 564 | else |
570 | tm2table(L, &ts); /* copy back updated values */ | ||
571 | lua_pushnumber(L, t); | 565 | lua_pushnumber(L, t); |
572 | } | ||
573 | } | 566 | } |
574 | return 1; | 567 | return 1; |
575 | } | 568 | } |