diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-12-15 16:17:49 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-12-15 16:17:49 -0200 |
commit | 43c61fc11381a20376c15a6c0fd4f53912c43ccc (patch) | |
tree | 93d486d2ea7ad760d374a0c6779b78267b05c6e3 /loslib.c | |
parent | ea6b1b42c7f13b15c05c9e2ddd47c3dcd4e600f9 (diff) | |
download | lua-43c61fc11381a20376c15a6c0fd4f53912c43ccc.tar.gz lua-43c61fc11381a20376c15a6c0fd4f53912c43ccc.tar.bz2 lua-43c61fc11381a20376c15a6c0fd4f53912c43ccc.zip |
details
Diffstat (limited to 'loslib.c')
-rw-r--r-- | loslib.c | 46 |
1 files changed, 23 insertions, 23 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loslib.c,v 1.13 2005/09/09 18:22:46 roberto Exp roberto $ | 2 | ** $Id: loslib.c,v 1.14 2005/10/21 13:47:42 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 | */ |
@@ -37,26 +37,26 @@ static int os_pushresult (lua_State *L, int i, const char *filename) { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | 39 | ||
40 | static int io_execute (lua_State *L) { | 40 | static int os_execute (lua_State *L) { |
41 | lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); | 41 | lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); |
42 | return 1; | 42 | return 1; |
43 | } | 43 | } |
44 | 44 | ||
45 | 45 | ||
46 | static int io_remove (lua_State *L) { | 46 | static int os_remove (lua_State *L) { |
47 | const char *filename = luaL_checkstring(L, 1); | 47 | const char *filename = luaL_checkstring(L, 1); |
48 | return os_pushresult(L, remove(filename) == 0, filename); | 48 | return os_pushresult(L, remove(filename) == 0, filename); |
49 | } | 49 | } |
50 | 50 | ||
51 | 51 | ||
52 | static int io_rename (lua_State *L) { | 52 | static int os_rename (lua_State *L) { |
53 | const char *fromname = luaL_checkstring(L, 1); | 53 | const char *fromname = luaL_checkstring(L, 1); |
54 | const char *toname = luaL_checkstring(L, 2); | 54 | const char *toname = luaL_checkstring(L, 2); |
55 | return os_pushresult(L, rename(fromname, toname) == 0, fromname); | 55 | return os_pushresult(L, rename(fromname, toname) == 0, fromname); |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | static int io_tmpname (lua_State *L) { | 59 | static int os_tmpname (lua_State *L) { |
60 | char buff[LUA_TMPNAMBUFSIZE]; | 60 | char buff[LUA_TMPNAMBUFSIZE]; |
61 | int err; | 61 | int err; |
62 | lua_tmpnam(buff, err); | 62 | lua_tmpnam(buff, err); |
@@ -67,13 +67,13 @@ static int io_tmpname (lua_State *L) { | |||
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
70 | static int io_getenv (lua_State *L) { | 70 | static int os_getenv (lua_State *L) { |
71 | lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ | 71 | lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ |
72 | return 1; | 72 | return 1; |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static int io_clock (lua_State *L) { | 76 | static int os_clock (lua_State *L) { |
77 | lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); | 77 | lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); |
78 | return 1; | 78 | return 1; |
79 | } | 79 | } |
@@ -123,7 +123,7 @@ static int getfield (lua_State *L, const char *key, int d) { | |||
123 | } | 123 | } |
124 | 124 | ||
125 | 125 | ||
126 | static int io_date (lua_State *L) { | 126 | static int os_date (lua_State *L) { |
127 | const char *s = luaL_optstring(L, 1, "%c"); | 127 | const char *s = luaL_optstring(L, 1, "%c"); |
128 | time_t t = lua_isnoneornil(L, 2) ? time(NULL) : | 128 | time_t t = lua_isnoneornil(L, 2) ? time(NULL) : |
129 | (time_t)luaL_checknumber(L, 2); | 129 | (time_t)luaL_checknumber(L, 2); |
@@ -159,7 +159,7 @@ static int io_date (lua_State *L) { | |||
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | static int io_time (lua_State *L) { | 162 | static int os_time (lua_State *L) { |
163 | time_t t; | 163 | time_t t; |
164 | if (lua_isnoneornil(L, 1)) /* called without args? */ | 164 | if (lua_isnoneornil(L, 1)) /* called without args? */ |
165 | t = time(NULL); /* get current time */ | 165 | t = time(NULL); /* get current time */ |
@@ -184,7 +184,7 @@ static int io_time (lua_State *L) { | |||
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | static int io_difftime (lua_State *L) { | 187 | static int os_difftime (lua_State *L) { |
188 | lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), | 188 | lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), |
189 | (time_t)(luaL_optnumber(L, 2, 0)))); | 189 | (time_t)(luaL_optnumber(L, 2, 0)))); |
190 | return 1; | 190 | return 1; |
@@ -193,7 +193,7 @@ static int io_difftime (lua_State *L) { | |||
193 | /* }====================================================== */ | 193 | /* }====================================================== */ |
194 | 194 | ||
195 | 195 | ||
196 | static int io_setloc (lua_State *L) { | 196 | static int os_setlocale (lua_State *L) { |
197 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, | 197 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, |
198 | LC_NUMERIC, LC_TIME}; | 198 | LC_NUMERIC, LC_TIME}; |
199 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", | 199 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", |
@@ -206,23 +206,23 @@ static int io_setloc (lua_State *L) { | |||
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | static int io_exit (lua_State *L) { | 209 | static int os_exit (lua_State *L) { |
210 | exit(luaL_optint(L, 1, EXIT_SUCCESS)); | 210 | exit(luaL_optint(L, 1, EXIT_SUCCESS)); |
211 | return 0; /* to avoid warnings */ | 211 | return 0; /* to avoid warnings */ |
212 | } | 212 | } |
213 | 213 | ||
214 | static const luaL_Reg syslib[] = { | 214 | static const luaL_Reg syslib[] = { |
215 | {"clock", io_clock}, | 215 | {"clock", os_clock}, |
216 | {"date", io_date}, | 216 | {"date", os_date}, |
217 | {"difftime", io_difftime}, | 217 | {"difftime", os_difftime}, |
218 | {"execute", io_execute}, | 218 | {"execute", os_execute}, |
219 | {"exit", io_exit}, | 219 | {"exit", os_exit}, |
220 | {"getenv", io_getenv}, | 220 | {"getenv", os_getenv}, |
221 | {"remove", io_remove}, | 221 | {"remove", os_remove}, |
222 | {"rename", io_rename}, | 222 | {"rename", os_rename}, |
223 | {"setlocale", io_setloc}, | 223 | {"setlocale", os_setlocale}, |
224 | {"time", io_time}, | 224 | {"time", os_time}, |
225 | {"tmpname", io_tmpname}, | 225 | {"tmpname", os_tmpname}, |
226 | {NULL, NULL} | 226 | {NULL, NULL} |
227 | }; | 227 | }; |
228 | 228 | ||