summaryrefslogtreecommitdiff
path: root/loslib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-08-05 16:30:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-08-05 16:30:37 -0300
commit2430d3cb28908fbca01001041a34d250f9668167 (patch)
treeee3d44d1da439ef9af970b69de7ac4401d2630c8 /loslib.c
parent6bddbbde7aaedbea2d5240964dc544f801655941 (diff)
downloadlua-2430d3cb28908fbca01001041a34d250f9668167.tar.gz
lua-2430d3cb28908fbca01001041a34d250f9668167.tar.bz2
lua-2430d3cb28908fbca01001041a34d250f9668167.zip
small changes (due to Rici Lake) to allow testing non-supported OS functions
Diffstat (limited to 'loslib.c')
-rw-r--r--loslib.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/loslib.c b/loslib.c
index d65a0b53..e52beb28 100644
--- a/loslib.c
+++ b/loslib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loslib.c,v $ 2** $Id: loslib.c,v 1.1 2004/07/09 15:47:48 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*/
@@ -38,7 +38,7 @@ static int pushresult (lua_State *L, int i, const char *filename) {
38 38
39 39
40static int io_execute (lua_State *L) { 40static int io_execute (lua_State *L) {
41 lua_pushinteger(L, system(luaL_checkstring(L, 1))); 41 lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
42 return 1; 42 return 1;
43} 43}
44 44
@@ -163,10 +163,10 @@ static int io_date (lua_State *L) {
163 163
164 164
165static int io_time (lua_State *L) { 165static int io_time (lua_State *L) {
166 time_t t;
166 if (lua_isnoneornil(L, 1)) /* called without args? */ 167 if (lua_isnoneornil(L, 1)) /* called without args? */
167 lua_pushnumber(L, time(NULL)); /* return current time */ 168 t = time(NULL); /* get current time */
168 else { 169 else {
169 time_t t;
170 struct tm ts; 170 struct tm ts;
171 luaL_checktype(L, 1, LUA_TTABLE); 171 luaL_checktype(L, 1, LUA_TTABLE);
172 lua_settop(L, 1); /* make sure table is at the top */ 172 lua_settop(L, 1); /* make sure table is at the top */
@@ -178,11 +178,11 @@ static int io_time (lua_State *L) {
178 ts.tm_year = getfield(L, "year", -1) - 1900; 178 ts.tm_year = getfield(L, "year", -1) - 1900;
179 ts.tm_isdst = getboolfield(L, "isdst"); 179 ts.tm_isdst = getboolfield(L, "isdst");
180 t = mktime(&ts); 180 t = mktime(&ts);
181 if (t == (time_t)(-1))
182 lua_pushnil(L);
183 else
184 lua_pushnumber(L, t);
185 } 181 }
182 if (t == (time_t)(-1))
183 lua_pushnil(L);
184 else
185 lua_pushnumber(L, t);
186 return 1; 186 return 1;
187} 187}
188 188