diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-07-12 15:54:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-07-12 15:54:53 -0300 |
commit | ce6b930464edd621ec95ddab2ce9ccb7ddae605a (patch) | |
tree | 0500d3ffa2985c978307104927d781185b7717ba | |
parent | ac7006d374928651874babf046030ba212290416 (diff) | |
download | lua-ce6b930464edd621ec95ddab2ce9ccb7ddae605a.tar.gz lua-ce6b930464edd621ec95ddab2ce9ccb7ddae605a.tar.bz2 lua-ce6b930464edd621ec95ddab2ce9ccb7ddae605a.zip |
`isdst' should be a boolean (and not 0/1!!)
-rw-r--r-- | liolib.c | 27 |
1 files changed, 21 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.11 2002/06/18 15:16:18 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.12 2002/06/26 16:37: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 | */ |
@@ -56,7 +56,7 @@ static int pushresult (lua_State *L, int i) { | |||
56 | static FILE *tofile (lua_State *L, int findex) { | 56 | static FILE *tofile (lua_State *L, int findex) { |
57 | FILE **f = (FILE **)lua_touserdata(L, findex); | 57 | FILE **f = (FILE **)lua_touserdata(L, findex); |
58 | if (f && lua_getmetatable(L, findex) && | 58 | if (f && lua_getmetatable(L, findex) && |
59 | lua_equal(L, -1, lua_upvalueindex(1))) { | 59 | lua_rawequal(L, -1, lua_upvalueindex(1))) { |
60 | lua_pop(L, 1); | 60 | lua_pop(L, 1); |
61 | return *f; | 61 | return *f; |
62 | } | 62 | } |
@@ -471,6 +471,21 @@ static void setfield (lua_State *L, const char *key, int value) { | |||
471 | lua_rawset(L, -3); | 471 | lua_rawset(L, -3); |
472 | } | 472 | } |
473 | 473 | ||
474 | static void setboolfield (lua_State *L, const char *key, int value) { | ||
475 | lua_pushstring(L, key); | ||
476 | lua_pushboolean(L, value); | ||
477 | lua_rawset(L, -3); | ||
478 | } | ||
479 | |||
480 | static int getboolfield (lua_State *L, const char *key) { | ||
481 | int res; | ||
482 | lua_pushstring(L, key); | ||
483 | lua_gettable(L, -2); | ||
484 | res = lua_toboolean(L, -1); | ||
485 | lua_pop(L, 1); | ||
486 | return res; | ||
487 | } | ||
488 | |||
474 | 489 | ||
475 | static int getfield (lua_State *L, const char *key, int d) { | 490 | static int getfield (lua_State *L, const char *key, int d) { |
476 | int res; | 491 | int res; |
@@ -512,7 +527,7 @@ static int io_date (lua_State *L) { | |||
512 | setfield(L, "year", stm->tm_year+1900); | 527 | setfield(L, "year", stm->tm_year+1900); |
513 | setfield(L, "wday", stm->tm_wday+1); | 528 | setfield(L, "wday", stm->tm_wday+1); |
514 | setfield(L, "yday", stm->tm_yday+1); | 529 | setfield(L, "yday", stm->tm_yday+1); |
515 | setfield(L, "isdst", stm->tm_isdst); | 530 | setboolfield(L, "isdst", stm->tm_isdst); |
516 | } | 531 | } |
517 | else { | 532 | else { |
518 | char b[256]; | 533 | char b[256]; |
@@ -537,9 +552,9 @@ static int io_time (lua_State *L) { | |||
537 | ts.tm_min = getfield(L, "min", 0); | 552 | ts.tm_min = getfield(L, "min", 0); |
538 | ts.tm_hour = getfield(L, "hour", 12); | 553 | ts.tm_hour = getfield(L, "hour", 12); |
539 | ts.tm_mday = getfield(L, "day", -2); | 554 | ts.tm_mday = getfield(L, "day", -2); |
540 | ts.tm_mon = getfield(L, "month", -2)-1; | 555 | ts.tm_mon = getfield(L, "month", -2) - 1; |
541 | ts.tm_year = getfield(L, "year", -2)-1900; | 556 | ts.tm_year = getfield(L, "year", -2) - 1900; |
542 | ts.tm_isdst = getfield(L, "isdst", -1); | 557 | ts.tm_isdst = getboolfield(L, "isdst"); |
543 | t = mktime(&ts); | 558 | t = mktime(&ts); |
544 | if (t == (time_t)(-1)) | 559 | if (t == (time_t)(-1)) |
545 | lua_pushnil(L); | 560 | lua_pushnil(L); |