aboutsummaryrefslogtreecommitdiff
path: root/loslib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-04-26 15:19:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-04-26 15:19:49 -0300
commitc351392940608702bfed0fa0a4c7d035ad31dbce (patch)
treedf75c22d4bb4a39ed7043e1204106d17b4cd6328 /loslib.c
parent18330b6091696f2900d89e8ddef6fb548a3ac84d (diff)
downloadlua-c351392940608702bfed0fa0a4c7d035ad31dbce.tar.gz
lua-c351392940608702bfed0fa0a4c7d035ad31dbce.tar.bz2
lua-c351392940608702bfed0fa0a4c7d035ad31dbce.zip
details
Diffstat (limited to 'loslib.c')
-rw-r--r--loslib.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/loslib.c b/loslib.c
index 26c1203a..3a1e8409 100644
--- a/loslib.c
+++ b/loslib.c
@@ -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
124static int os_date (lua_State *L) { 124static 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}