aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-22 14:57:13 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-22 14:57:13 -0200
commit1db05793a0793ae0b64cf809d4d1c4f98dba064a (patch)
tree7674078095112c835837aa2d644956af7783b874 /liolib.c
parentaf97be026b792308f972870019dcaaf4c945e071 (diff)
downloadlua-1db05793a0793ae0b64cf809d4d1c4f98dba064a.tar.gz
lua-1db05793a0793ae0b64cf809d4d1c4f98dba064a.tar.bz2
lua-1db05793a0793ae0b64cf809d4d1c4f98dba064a.zip
`time' does not need to correct its table argument (use `date' for that)
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/liolib.c b/liolib.c
index 907c77b4..6cb555af 100644
--- a/liolib.c
+++ b/liolib.c
@@ -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
509static 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
522static int io_date (lua_State *L) { 509static 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}