The Battle for Wesnoth  1.15.1+dev
Macros | Functions | Variables
loslib.cpp File Reference
#include "lprefix.h"
#include <errno.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
Include dependency graph for loslib.cpp:

Go to the source code of this file.

Macros

#define loslib_c
 
#define LUA_LIB
 
#define L_STRFTIMEC89   "aAbBcdHIjmMpSUwWxXyYZ%"
 
#define L_STRFTIMEC99
 
#define L_STRFTIMEWIN
 
#define LUA_STRFTIMEOPTIONS   L_STRFTIMEC99
 
#define l_timet   lua_Integer
 
#define l_pushtime(L, t)   lua_pushinteger(L,(lua_Integer)(t))
 
#define l_gmtime(t, r)   ((void)(r)->tm_sec, gmtime(t))
 
#define l_localtime(t, r)   ((void)(r)->tm_sec, localtime(t))
 
#define LUA_TMPNAMBUFSIZE   L_tmpnam
 
#define lua_tmpnam(b, e)   { e = (tmpnam(b) == NULL); }
 
#define L_MAXDATEFIELD   (INT_MAX / 2)
 
#define SIZETIMEFMT   250
 

Functions

static time_t l_checktime (lua_State *L, int arg)
 
static int os_execute (lua_State *L)
 
static int os_remove (lua_State *L)
 
static int os_rename (lua_State *L)
 
static int os_tmpname (lua_State *L)
 
static int os_getenv (lua_State *L)
 
static int os_clock (lua_State *L)
 
static void setfield (lua_State *L, const char *key, int value)
 
static void setboolfield (lua_State *L, const char *key, int value)
 
static void setallfields (lua_State *L, struct tm *stm)
 
static int getboolfield (lua_State *L, const char *key)
 
static int getfield (lua_State *L, const char *key, int d, int delta)
 
static const char * checkoption (lua_State *L, const char *conv, ptrdiff_t convlen, char *buff)
 
static int os_date (lua_State *L)
 
static int os_time (lua_State *L)
 
static int os_difftime (lua_State *L)
 
static int os_setlocale (lua_State *L)
 
static int os_exit (lua_State *L)
 
LUAMOD_API int luaopen_os (lua_State *L)
 

Variables

static const luaL_Reg syslib []
 

Macro Definition Documentation

◆ l_gmtime

#define l_gmtime (   t,
 
)    ((void)(r)->tm_sec, gmtime(t))

Definition at line 92 of file loslib.cpp.

Referenced by os_date().

◆ l_localtime

#define l_localtime (   t,
 
)    ((void)(r)->tm_sec, localtime(t))

Definition at line 93 of file loslib.cpp.

Referenced by os_date().

◆ L_MAXDATEFIELD

#define L_MAXDATEFIELD   (INT_MAX / 2)

Definition at line 236 of file loslib.cpp.

Referenced by getfield().

◆ l_pushtime

#define l_pushtime (   L,
  t 
)    lua_pushinteger(L,(lua_Integer)(t))

Definition at line 67 of file loslib.cpp.

Referenced by os_time().

◆ L_STRFTIMEC89

#define L_STRFTIMEC89   "aAbBcdHIjmMpSUwWxXyYZ%"

Definition at line 34 of file loslib.cpp.

◆ L_STRFTIMEC99

#define L_STRFTIMEC99
Value:
"aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%" \
"||" "EcECExEXEyEY" "OdOeOHOIOmOMOSOuOUOVOwOWOy" /* two-char options */

Definition at line 37 of file loslib.cpp.

◆ L_STRFTIMEWIN

#define L_STRFTIMEWIN
Value:
"aAbBcdHIjmMpSUwWxXyYzZ%" \
"||" "#c#x#d#H#I#j#m#M#S#U#w#W#y#Y" /* two-char options */

Definition at line 41 of file loslib.cpp.

◆ l_timet

#define l_timet   lua_Integer

Definition at line 66 of file loslib.cpp.

Referenced by os_time().

◆ loslib_c

#define loslib_c

Definition at line 7 of file loslib.cpp.

◆ LUA_LIB

#define LUA_LIB

Definition at line 8 of file loslib.cpp.

◆ LUA_STRFTIMEOPTIONS

#define LUA_STRFTIMEOPTIONS   L_STRFTIMEC99

Definition at line 49 of file loslib.cpp.

Referenced by checkoption().

◆ lua_tmpnam

#define lua_tmpnam (   b,
  e 
)    { e = (tmpnam(b) == NULL); }

Definition at line 131 of file loslib.cpp.

Referenced by os_tmpname().

◆ LUA_TMPNAMBUFSIZE

#define LUA_TMPNAMBUFSIZE   L_tmpnam

Definition at line 130 of file loslib.cpp.

Referenced by os_tmpname().

◆ SIZETIMEFMT

#define SIZETIMEFMT   250

Definition at line 280 of file loslib.cpp.

Referenced by os_date().

Function Documentation

◆ checkoption()

static const char* checkoption ( lua_State L,
const char *  conv,
ptrdiff_t  convlen,
char *  buff 
)
static

Definition at line 260 of file loslib.cpp.

References lua_pushfstring(), LUA_STRFTIMEOPTIONS, and luaL_argerror().

Referenced by os_date().

◆ getboolfield()

static int getboolfield ( lua_State L,
const char *  key 
)
static

Definition at line 226 of file loslib.cpp.

References lua_getfield(), lua_pop, LUA_TNIL, and lua_toboolean().

Referenced by os_time().

◆ getfield()

static int getfield ( lua_State L,
const char *  key,
int  d,
int  delta 
)
static

Definition at line 239 of file loslib.cpp.

References d, L_MAXDATEFIELD, lua_getfield(), lua_pop, LUA_TNIL, lua_tointegerx(), luaL_error(), and t.

Referenced by os_time().

◆ l_checktime()

static time_t l_checktime ( lua_State L,
int  arg 
)
static

Definition at line 69 of file loslib.cpp.

References luaL_argcheck, luaL_checkinteger(), and t.

Referenced by os_date(), and os_difftime().

◆ luaopen_os()

LUAMOD_API int luaopen_os ( lua_State L)

Definition at line 405 of file loslib.cpp.

References luaL_newlib.

Referenced by lua_kernel_base::lua_kernel_base().

◆ os_clock()

static int os_clock ( lua_State L)
static

Definition at line 183 of file loslib.cpp.

References lua_pushnumber().

◆ os_date()

static int os_date ( lua_State L)
static

◆ os_difftime()

static int os_difftime ( lua_State L)
static

Definition at line 351 of file loslib.cpp.

References l_checktime(), and lua_pushnumber().

◆ os_execute()

static int os_execute ( lua_State L)
static

Definition at line 141 of file loslib.cpp.

References lua_pushboolean(), luaL_execresult(), and luaL_optstring.

◆ os_exit()

static int os_exit ( lua_State L)
static

Definition at line 373 of file loslib.cpp.

References lua_close(), lua_isboolean, lua_toboolean(), and luaL_optinteger().

◆ os_getenv()

static int os_getenv ( lua_State L)
static

Definition at line 177 of file loslib.cpp.

References lua_pushstring(), and luaL_checkstring.

◆ os_remove()

static int os_remove ( lua_State L)
static

Definition at line 153 of file loslib.cpp.

References luaL_checkstring, and luaL_fileresult().

◆ os_rename()

static int os_rename ( lua_State L)
static

Definition at line 159 of file loslib.cpp.

References luaL_checkstring, and luaL_fileresult().

◆ os_setlocale()

static int os_setlocale ( lua_State L)
static

Definition at line 361 of file loslib.cpp.

References lua_pushstring(), luaL_checkoption(), and luaL_optstring.

◆ os_time()

static int os_time ( lua_State L)
static

◆ os_tmpname()

static int os_tmpname ( lua_State L)
static

Definition at line 166 of file loslib.cpp.

References lg::err(), lua_pushstring(), lua_tmpnam, LUA_TMPNAMBUFSIZE, and luaL_error().

◆ setallfields()

static void setallfields ( lua_State L,
struct tm *  stm 
)
static

Definition at line 213 of file loslib.cpp.

References setboolfield(), and setfield().

Referenced by os_date(), and os_time().

◆ setboolfield()

static void setboolfield ( lua_State L,
const char *  key,
int  value 
)
static

Definition at line 202 of file loslib.cpp.

References lua_pushboolean(), and lua_setfield().

Referenced by setallfields().

◆ setfield()

static void setfield ( lua_State L,
const char *  key,
int  value 
)
static

Definition at line 197 of file loslib.cpp.

References lua_pushinteger(), and lua_setfield().

Referenced by setallfields().

Variable Documentation

◆ syslib

const luaL_Reg syslib[]
static
Initial value:
= {
{"clock", os_clock},
{"date", os_date},
{"difftime", os_difftime},
{"execute", os_execute},
{"exit", os_exit},
{"getenv", os_getenv},
{"remove", os_remove},
{"rename", os_rename},
{"setlocale", os_setlocale},
{"time", os_time},
{"tmpname", os_tmpname},
{NULL, NULL}
}
static int os_time(lua_State *L)
Definition: loslib.cpp:325
static int os_execute(lua_State *L)
Definition: loslib.cpp:141
static int os_tmpname(lua_State *L)
Definition: loslib.cpp:166
static int os_difftime(lua_State *L)
Definition: loslib.cpp:351
static int os_getenv(lua_State *L)
Definition: loslib.cpp:177
static int os_date(lua_State *L)
Definition: loslib.cpp:283
static int os_rename(lua_State *L)
Definition: loslib.cpp:159
static int os_exit(lua_State *L)
Definition: loslib.cpp:373
static int os_remove(lua_State *L)
Definition: loslib.cpp:153
static int os_clock(lua_State *L)
Definition: loslib.cpp:183
static int os_setlocale(lua_State *L)
Definition: loslib.cpp:361

Definition at line 386 of file loslib.cpp.