Lines Matching refs:L
23 static int os_pushresult (lua_State *L, int i, const char *filename) { in os_pushresult() argument
26 lua_pushboolean(L, 1); in os_pushresult()
30 lua_pushnil(L); in os_pushresult()
31 lua_pushfstring(L, "%s: %s", filename, strerror(en)); in os_pushresult()
32 lua_pushinteger(L, en); in os_pushresult()
38 static int os_execute (lua_State *L) { in os_execute() argument
39 lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); in os_execute()
44 static int os_remove (lua_State *L) { in os_remove() argument
45 const char *filename = luaL_checkstring(L, 1); in os_remove()
46 return os_pushresult(L, remove(filename) == 0, filename); in os_remove()
50 static int os_rename (lua_State *L) { in os_rename() argument
51 const char *fromname = luaL_checkstring(L, 1); in os_rename()
52 const char *toname = luaL_checkstring(L, 2); in os_rename()
53 return os_pushresult(L, rename(fromname, toname) == 0, fromname); in os_rename()
57 static int os_tmpname (lua_State *L) { in os_tmpname() argument
62 return luaL_error(L, "unable to generate a unique filename"); in os_tmpname()
63 lua_pushstring(L, buff); in os_tmpname()
68 static int os_getenv (lua_State *L) { in os_getenv() argument
69 lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ in os_getenv()
74 static int os_clock (lua_State *L) { in os_clock() argument
75 lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); in os_clock()
88 static void setfield (lua_State *L, const char *key, int value) { in setfield() argument
89 lua_pushinteger(L, value); in setfield()
90 lua_setfield(L, -2, key); in setfield()
93 static void setboolfield (lua_State *L, const char *key, int value) { in setboolfield() argument
96 lua_pushboolean(L, value); in setboolfield()
97 lua_setfield(L, -2, key); in setboolfield()
100 static int getboolfield (lua_State *L, const char *key) { in getboolfield() argument
102 lua_getfield(L, -1, key); in getboolfield()
103 res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); in getboolfield()
104 lua_pop(L, 1); in getboolfield()
109 static int getfield (lua_State *L, const char *key, int d) { in getfield() argument
111 lua_getfield(L, -1, key); in getfield()
112 if (lua_isnumber(L, -1)) in getfield()
113 res = (int)lua_tointeger(L, -1); in getfield()
116 return luaL_error(L, "field " LUA_QS " missing in date table", key); in getfield()
119 lua_pop(L, 1); in getfield()
124 static int os_date (lua_State *L) { in os_date() argument
125 const char *s = luaL_optstring(L, 1, "%c"); in os_date()
126 time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); in os_date()
135 lua_pushnil(L); in os_date()
137 lua_createtable(L, 0, 9); /* 9 = number of fields */ in os_date()
138 setfield(L, "sec", stm->tm_sec); in os_date()
139 setfield(L, "min", stm->tm_min); in os_date()
140 setfield(L, "hour", stm->tm_hour); in os_date()
141 setfield(L, "day", stm->tm_mday); in os_date()
142 setfield(L, "month", stm->tm_mon+1); in os_date()
143 setfield(L, "year", stm->tm_year+1900); in os_date()
144 setfield(L, "wday", stm->tm_wday+1); in os_date()
145 setfield(L, "yday", stm->tm_yday+1); in os_date()
146 setboolfield(L, "isdst", stm->tm_isdst); in os_date()
152 luaL_buffinit(L, &b); in os_date()
170 static int os_time (lua_State *L) { in os_time() argument
172 if (lua_isnoneornil(L, 1)) /* called without args? */ in os_time()
176 luaL_checktype(L, 1, LUA_TTABLE); in os_time()
177 lua_settop(L, 1); /* make sure table is at the top */ in os_time()
178 ts.tm_sec = getfield(L, "sec", 0); in os_time()
179 ts.tm_min = getfield(L, "min", 0); in os_time()
180 ts.tm_hour = getfield(L, "hour", 12); in os_time()
181 ts.tm_mday = getfield(L, "day", -1); in os_time()
182 ts.tm_mon = getfield(L, "month", -1) - 1; in os_time()
183 ts.tm_year = getfield(L, "year", -1) - 1900; in os_time()
184 ts.tm_isdst = getboolfield(L, "isdst"); in os_time()
188 lua_pushnil(L); in os_time()
190 lua_pushnumber(L, (lua_Number)t); in os_time()
195 static int os_difftime (lua_State *L) { in os_difftime() argument
196 lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), in os_difftime()
197 (time_t)(luaL_optnumber(L, 2, 0)))); in os_difftime()
204 static int os_setlocale (lua_State *L) { in os_setlocale() argument
209 const char *l = luaL_optstring(L, 1, NULL); in os_setlocale()
210 int op = luaL_checkoption(L, 2, "all", catnames); in os_setlocale()
211 lua_pushstring(L, setlocale(cat[op], l)); in os_setlocale()
216 static int os_exit (lua_State *L) { in os_exit() argument
217 exit(luaL_optint(L, 1, EXIT_SUCCESS)); in os_exit()
239 LUALIB_API int luaopen_os (lua_State *L) { in luaopen_os() argument
240 luaL_register(L, LUA_OSLIBNAME, syslib); in luaopen_os()