diff options
| -rw-r--r-- | loslib.c | 8 |
1 files changed, 3 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loslib.c,v 1.17 2006/01/27 13:54:31 roberto Exp roberto $ | 2 | ** $Id: loslib.c,v 1.18 2006/03/09 18:08:22 roberto Exp roberto $ |
| 3 | ** Standard Operating System library | 3 | ** Standard Operating System library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -123,8 +123,7 @@ static int getfield (lua_State *L, const char *key, int d) { | |||
| 123 | 123 | ||
| 124 | static int os_date (lua_State *L) { | 124 | static int os_date (lua_State *L) { |
| 125 | const char *s = luaL_optstring(L, 1, "%c"); | 125 | const char *s = luaL_optstring(L, 1, "%c"); |
| 126 | time_t t = lua_isnoneornil(L, 2) ? time(NULL) : | 126 | time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); |
| 127 | (time_t)luaL_checknumber(L, 2); | ||
| 128 | struct tm *stm; | 127 | struct tm *stm; |
| 129 | if (*s == '!') { /* UTC? */ | 128 | if (*s == '!') { /* UTC? */ |
| 130 | stm = gmtime(&t); | 129 | stm = gmtime(&t); |
| @@ -196,9 +195,8 @@ static int os_setlocale (lua_State *L) { | |||
| 196 | LC_NUMERIC, LC_TIME}; | 195 | LC_NUMERIC, LC_TIME}; |
| 197 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", | 196 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", |
| 198 | "numeric", "time", NULL}; | 197 | "numeric", "time", NULL}; |
| 199 | const char *l = lua_tostring(L, 1); | 198 | const char *l = luaL_optstring(L, 1, NULL); |
| 200 | int op = luaL_checkoption(L, 2, "all", catnames); | 199 | int op = luaL_checkoption(L, 2, "all", catnames); |
| 201 | luaL_argcheck(L, l || lua_isnoneornil(L, 1), 1, "string expected"); | ||
| 202 | lua_pushstring(L, setlocale(cat[op], l)); | 200 | lua_pushstring(L, setlocale(cat[op], l)); |
| 203 | return 1; | 201 | return 1; |
| 204 | } | 202 | } |
