LUAZIP_API int luaopen_zip (lua_State *L) { createmeta(L); lua_pushvalue(L, -1); luaL_openlib(L, LUA_ZIPLIBNAME, ziplib, 1); set_info(L); return 1; }
LUAZIP_API int luaopen_zip (lua_State *L) { lua_pop(L,createmeta(L)); lua_newtable(L); luaL_setfuncs(L, ziplib, 0); set_info(L); return 1; }
LUALIB_API int luaopen_sys (lua_State *L) { luaL_register(L, LUA_SYSLIBNAME, sys_lib); createmeta(L); luaopen_sys_mem(L); luaopen_sys_thread(L); #ifdef _WIN32 #ifdef _WIN32_WCE is_WinNT = 1; #else /* Is Win32 NT platform? */ { OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); is_WinNT = (GetVersionEx(&osvi) && osvi.dwPlatformId == VER_PLATFORM_WIN32_NT); } #endif luaopen_sys_win32(L); #else /* Ignore sigpipe or it will crash us */ signal_set(SIGPIPE, SIG_IGN); /* To interrupt blocking syscalls */ signal_set(SYS_SIGINTR, NULL); #endif return 1; }
LUALIB_API int luaopen_io (lua_State *L) { createmeta(L); #if LUA_OPTIMIZE_MEMORY != 2 /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ newfenv(L, io_fclose); lua_replace(L, LUA_ENVIRONINDEX); /* open library */ luaL_register(L, LUA_IOLIBNAME, iolib); newfenv(L, io_noclose); /* close function for default files */ #else luaL_register_light(L, LUA_IOLIBNAME, iolib); lua_pushvalue(L, -1); lua_setmetatable(L, -2); #endif /* create (and set) default files */ createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdout, IO_OUTPUT, "stdout"); createstdfile(L, stderr, IO_STDERR, "stderr"); #if LUA_OPTIMIZE_MEMORY != 2 lua_pop(L, 1); /* pop environment for default files */ lua_getfield(L, -1, "popen"); newfenv(L, io_pclose); /* create environment for 'popen' */ lua_setfenv(L, -2); /* set fenv for 'popen' */ lua_pop(L, 1); /* pop 'popen' */ #endif return 1; }
LUAMOD_API int luaopen_io (lua_State *L) { #if !LUA_USE_ROTABLE luaL_newlib(L, iolib); /* new module */ createmeta(L); /* create (and set) default files */ createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdout, IO_OUTPUT, "stdout"); createstdfile(L, stderr, NULL, "stderr"); #else luaL_newlib(L, io_load_funcs); /* new module */ lua_pushvalue(L, -1); lua_setmetatable(L, -2); luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ lua_pushvalue(L, -1); /* push metatable */ lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ luaL_setfuncs(L, flib_load_funcs, 0); /* add file methods to new metatable */ lua_pop(L, 1); /* pop new metatable */ /* create (and set) default files */ createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdout, IO_OUTPUT, "stdout"); createstdfile(L, stderr, NULL, "stderr"); #endif return 1; }
LUALIB_API int luaopen_polarssl (lua_State *L) { luaL_register(L, LUA_POLARSSLLIBNAME, polarssl_lib); createmeta(L); return 1; }
LUALIB_API int luaopen_io (lua_State *L) { createmeta(L); /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ lua_createtable(L, 2, 1); lua_replace(L, LUA_ENVIRONINDEX); /* open library */ luaL_register(L, LUA_IOLIBNAME, iolib); /* create (and set) default files */ createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdout, IO_OUTPUT, "stdout"); createstdfile(L, stderr, 0, "stderr"); #if USE_POPEN /* create environment for 'popen' */ lua_getfield(L, -1, "popen"); lua_createtable(L, 0, 1); lua_pushcfunction(L, io_pclose); lua_setfield(L, -2, "__close"); lua_setfenv(L, -2); lua_pop(L, 1); /* pop 'popen' */ #endif /* set default close function */ lua_pushcfunction(L, io_fclose); lua_setfield(L, LUA_ENVIRONINDEX, "__close"); return 1; }
LUALIB_API int luaopen_lzlib (lua_State *L) { createmeta(L); luaL_openlib(L, "lzlib", R, 0); lua_pushliteral(L,"version"); /** version */ lua_pushliteral(L,"pre-alpha"); lua_settable(L,-3); return 1; }
LUAMOD_API int luaopen_io(lua_State *L) { luaL_newlib(L, iolib); /* new module */ createmeta(L); /* create (and set) default files */ createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdout, IO_OUTPUT, "stdout"); createstdfile(L, stderr, NULL, "stderr"); return 1; }
int luaopen_sqlite3(lua_State* L) { luaL_newlib(L, sqlite3lib); lua_pushinteger(L, SQLITE_INTEGER); lua_setfield(L, -2, "INTEGER"); lua_pushinteger(L, SQLITE_FLOAT); lua_setfield(L, -2, "FLOAT"); lua_pushinteger(L, SQLITE_BLOB); lua_setfield(L, -2, "BLOB"); lua_pushinteger(L, SQLITE_NULL); lua_setfield(L, -2, "NULL"); lua_pushinteger(L, SQLITE3_TEXT); lua_setfield(L, -2, "TEXT"); createmeta(L, MT_CONN, connlib); createmeta(L, MT_STMT, stmtlib); return 1; }
LUALIB_API int luaopen_io (lua_State *L) { luaL_openlib(L, LUA_OSLIBNAME, syslib, 0); createmeta(L); lua_pushvalue(L, -1); luaL_openlib(L, LUA_IOLIBNAME, iolib, 1); /* put predefined file handles into `io' table */ registerfile(L, stdin, "stdin", IO_INPUT); registerfile(L, stdout, "stdout", IO_OUTPUT); registerfile(L, stderr, "stderr", NULL); return 1; }
int open_iolibext (lua_State *L) { #ifdef LuajitTeX return luaopen_io(L); #else luaL_newlib(L, iolib); /* new module */ createmeta(L); /* create (and set) default files */ createstdfile(L, stdin, IO_INPUT, "stdin"); createstdfile(L, stdout, IO_OUTPUT, "stdout"); createstdfile(L, stderr, NULL, "stderr"); return 1; #endif }
LUACURL_API int luaopen_luacurl (lua_State *L) { curl_global_init(CURL_GLOBAL_ALL); /* In windows, this will init the winsock stuff */ createmeta(L); luaL_openlib (L, 0, luacurl_meths, 0); luaL_openlib (L, LUACURL_LIBNAME, luacurl_funcs, 0); set_info(L); setcurlerrors(L); setcurloptions(L); setcurlvalues(L); setcurlinfo(L); return 1; }
LUALIB_API int lua_iolibopen (lua_State *L) { createmeta(L); luaL_opennamedlib(L, LUA_OSLIBNAME, syslib, 0); lua_pushliteral(L, FILEHANDLE); /* S: FH */ lua_rawget(L, LUA_REGISTRYINDEX); /* S: mt */ lua_pushvalue(L, -1); /* S: mt mt */ luaL_opennamedlib(L, LUA_IOLIBNAME, iolib, 1); /* S: mt */ lua_pushliteral(L, LUA_IOLIBNAME); /* S: `io' mt */ lua_gettable(L, LUA_GLOBALSINDEX); /* S: io mt */ /* put predefined file handles into `io' table */ registerfile(L, stdin, "stdin", IO_INPUT); registerfile(L, stdout, "stdout", IO_OUTPUT); registerfile(L, stderr, "stderr", NULL); lua_pop(L, 2); /* S: empty */ return 0; }
void imlua_open_image (lua_State *L) { /* "im" table is at the top of the stack */ createmeta(L); luaL_register(L, NULL, imimage_lib); #ifdef IMLUA_USELOH #include "im_image.loh" #else #ifdef IMLUA_USELH #include "im_image.lh" #else luaL_dofile(L, "im_image.lua"); #endif #endif }
LUALIB_API int luaopen_io (lua_State *L) { createmeta(L); /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ newfenv(L, io_fclose); lua_replace(L, LUA_ENVIRONINDEX); /* open library */ luaL_register(L, LUA_IOLIBNAME, iolib); /* create (and set) default files */ newfenv(L, io_noclose); /* close function for default files */ // createstdfile(L, stdin, IO_INPUT, "stdin"); // createstdfile(L, stdout, IO_OUTPUT, "stdout"); // createstdfile(L, stderr, 0, "stderr"); lua_pop(L, 1); /* pop environment for default files */ // lua_getfield(L, -1, "popen"); // newfenv(L, io_pclose); /* create environment for 'popen' */ // lua_setfenv(L, -2); /* set fenv for 'popen' */ // lua_pop(L, 1); /* pop 'popen' */ return 1; }
int luaopen_lpc (lua_State *L) { createmeta(L); #if LUA_VERSION_NUM < 502 luaL_openlib(L, "lpc", lpclib, 0); /* create environment for 'run' */ lua_getfield(L, -1, "run"); lua_createtable(L, 0, 1); lua_pushcfunction(L, io_fclose); lua_setfield(L, -2, "__close"); lua_setfenv(L, -2); lua_pop(L, 1); /* pop 'run' */ #else luaL_newlib(L, lpclib); #endif set_info(L); return 1; }
int luaopen_iostring(lua_State *L) { createmeta(L); luaL_openlib(L, LUAIOSTRINGLIBNAME, iostringlib, 0); return 0; }
void imlua_open_palette (lua_State *L) { /* im table is at the top of the stack */ createmeta(L); imlua_register_funcs(L, impalette_lib); }
int imlua_open_capture(lua_State *L) { createmeta(L); luaL_register(L, "im", imcapture_lib); /* leave "im" table at the top of the stack */ return 1; }
LUAMOD_API int luaopen_io (lua_State *L) { luaL_newlib(L, iolib); /* new module */ createmeta(L); /* create (and set) default files */ return 1; }
void createDocMetaTable(lua_State *L) { createmeta(L,LUATIDY_HANDLE); luaL_openlib (L, 0, luatidy_meths, 0); lua_pop(L,1); }
/* * Returns: processors_load_average (number), is_per_cpu (boolean) */ static int sys_loadavg (lua_State *L) { double loadavg; #ifndef _WIN32 const int res = 0; if (getloadavg(&loadavg, 1) == 1) { const int is_per_cpu = 1; #else const int res = getloadavg(&loadavg); if (!res) { const int is_per_cpu = 0; #endif lua_pushnumber(L, (lua_Number) loadavg); lua_pushboolean(L, is_per_cpu); return 2; } return sys_seterror(L, res); } /* * Arguments: [number_of_files (number)] * Returns: number_of_files (number) */ static int sys_limit_nfiles (lua_State *L) { #ifndef _WIN32 const int narg = lua_gettop(L); struct rlimit rlim; rlim.rlim_max = 0; getrlimit(RLIMIT_NOFILE, &rlim); lua_pushinteger(L, rlim.rlim_max); if (narg != 0) { const int n = lua_tointeger(L, 1); rlim.rlim_cur = rlim.rlim_max = n; if (setrlimit(RLIMIT_NOFILE, &rlim)) return sys_seterror(L, 0); } return 1; #else (void) L; lua_pushinteger(L, -1); return 1; #endif } /* * Arguments: string * Returns: number */ static int sys_toint (lua_State *L) { const char *s = lua_tostring(L, 1); int num = 0, sign = 1; if (s) { switch (*s) { case '-': sign = -1; case '+': ++s; } while (*s >= '0' && *s <= '9') num = (num << 3) + (num << 1) + (*s++ & ~'0'); } lua_pushinteger(L, sign * num); return 1; } /* * Arguments: error_handler (function), function, any ... * Returns: status (boolean), any ... */ static int sys_xpcall (lua_State *L) { const int status = lua_pcall(L, lua_gettop(L) - 2, LUA_MULTRET, 1); lua_pushboolean(L, !status); lua_insert(L, 2); return lua_gettop(L) - 1; } #include "isa/fcgi/sys_fcgi.c" #include "mem/sys_mem.c" #include "thread/sys_thread.c" #ifndef _WIN32 #include "sys_unix.c" #else #include "win32/sys_win32.c" #endif #include "sys_file.c" #include "sys_date.c" #include "sys_env.c" #include "sys_evq.c" #include "sys_fs.c" #include "sys_log.c" #include "sys_proc.c" #include "sys_rand.c" static luaL_Reg sys_lib[] = { {"strerror", sys_strerror}, {"nprocs", sys_nprocs}, {"loadavg", sys_loadavg}, {"limit_nfiles", sys_limit_nfiles}, {"toint", sys_toint}, {"xpcall", sys_xpcall}, DATE_METHODS, ENV_METHODS, EVQ_METHODS, FCGI_METHODS, FD_METHODS, FS_METHODS, LOG_METHODS, PROC_METHODS, RAND_METHODS, #ifndef _WIN32 UNIX_METHODS, #endif {NULL, NULL} }; /* * Arguments: ..., sys_lib (table) */ static void createmeta (lua_State *L) { const int top = lua_gettop(L); const struct meta_s { const char *tname; luaL_Reg *meth; int is_index; } meta[] = { {DIR_TYPENAME, dir_meth, 0}, {EVQ_TYPENAME, evq_meth, 1}, {FD_TYPENAME, fd_meth, 1}, {PERIOD_TYPENAME, period_meth, 1}, {PID_TYPENAME, pid_meth, 1}, {LOG_TYPENAME, log_meth, 0}, {RAND_TYPENAME, rand_meth, 0}, }; int i; for (i = 0; i < (int) (sizeof(meta) / sizeof(struct meta_s)); ++i) { luaL_newmetatable(L, meta[i].tname); if (meta[i].is_index) { lua_pushvalue(L, -1); /* push metatable */ lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ } luaL_setfuncs(L, meta[i].meth, 0); lua_pop(L, 1); } /* Predefined file handles */ luaL_getmetatable(L, FD_TYPENAME); { const char *std[] = {"stdin", "stdout", "stderr"}; for (i = 3; i--; ) { #ifndef _WIN32 const fd_t fd = i; #else const fd_t fd = GetStdHandle(i == 0 ? STD_INPUT_HANDLE : (i == 1 ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE)); #endif lua_pushstring(L, std[i]); lua_boxinteger(L, fd); lua_pushvalue(L, -3); /* metatable */ lua_pushboolean(L, 1); lua_rawseti(L, -2, (int) fd); /* don't close std. handles */ lua_setmetatable(L, -2); lua_rawset(L, top); } } lua_settop(L, top); } LUALIB_API int luaopen_sys (lua_State *L) { luaL_register(L, LUA_SYSLIBNAME, sys_lib); createmeta(L); signal_init(); #ifdef _WIN32 luaopen_sys_win32(L); #endif luaopen_sys_mem(L); luaopen_sys_thread(L); return 1; }
void imlua_open_palette (lua_State *L) { /* "im" table is at the top of the stack */ createmeta(L); luaL_register(L, NULL, impalette_lib); }
int imlua_open_capture(lua_State *L) { createmeta(L); imlua_register_lib(L, imcapture_lib); /* leave im table at the top of the stack */ return 1; }