32 #if !defined(l_checkmode) 35 #if !defined(L_MODEEXT) 41 return (*mode !=
'\0' && strchr(
"rwa", *(mode++)) != NULL &&
42 (*mode !=
'+' || ((
void)(++mode), 1)) &&
43 (strspn(mode,
L_MODEEXT) == strlen(mode)));
55 #if !defined(l_checkmodep) 57 #define l_checkmodep(m) ((m[0] == 'r' || m[0] == 'w') && m[1] == '\0') 63 #if defined(LUA_USE_POSIX) 65 #define l_popen(L,c,m) (fflush(NULL), popen(c,m)) 66 #define l_pclose(L,file) (pclose(file)) 68 #elif defined(LUA_USE_WINDOWS) 70 #define l_popen(L,c,m) (_popen(c,m)) 71 #define l_pclose(L,file) (_pclose(file)) 76 #define l_popen(L,c,m) \ 78 luaL_error(L, "'popen' not supported"), \ 80 #define l_pclose(L,file) ((void)L, (void)file, -1) 91 #if defined(LUA_USE_POSIX) 92 #define l_getc(f) getc_unlocked(f) 93 #define l_lockfile(f) flockfile(f) 94 #define l_unlockfile(f) funlockfile(f) 96 #define l_getc(f) getc(f) 97 #define l_lockfile(f) ((void)0) 98 #define l_unlockfile(f) ((void)0) 110 #if !defined(l_fseek) 112 #if defined(LUA_USE_POSIX) 114 #include <sys/types.h> 116 #define l_fseek(f,o,w) fseeko(f,o,w) 117 #define l_ftell(f) ftello(f) 118 #define l_seeknum off_t 120 #elif defined(LUA_USE_WINDOWS) && !defined(_CRTIMP_TYPEINFO) \ 121 && defined(_MSC_VER) && (_MSC_VER >= 1400) 124 #define l_fseek(f,o,w) _fseeki64(f,o,w) 125 #define l_ftell(f) _ftelli64(f) 126 #define l_seeknum __int64 131 #define l_fseek(f,o,w) fseek(f,o,w) 132 #define l_ftell(f) ftell(f) 133 #define l_seeknum long 143 #define IO_PREFIX "_IO_" 144 #define IOPREF_LEN (sizeof(IO_PREFIX)/sizeof(char) - 1) 145 #define IO_INPUT (IO_PREFIX "input") 146 #define IO_OUTPUT (IO_PREFIX "output") 152 #define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE)) 154 #define isclosed(p) ((p)->closef == NULL) 184 luaL_error(L,
"attempt to use a closed file");
242 int res = fclose(p->
f);
257 p->
f = fopen(fname, mode);
259 luaL_error(L,
"cannot open file '%s' (%s)", fname, strerror(errno));
267 const char *md = mode;
269 p->
f = fopen(filename, mode);
346 #define MAXARGLINE 250 415 #if !defined (L_MAXLENNUM) 416 #define L_MAXLENNUM 200 438 rn->
buff[rn->
n++] = rn->
c;
449 if (rn->
c ==
set[0] || rn->
c ==
set[1])
460 while ((hex ? isxdigit(rn->
c) : isdigit(rn->
c)) &&
nextc(rn))
480 do { rn.
c =
l_getc(rn.
f); }
while (isspace(rn.
c));
482 if (
test2(&rn,
"00")) {
483 if (
test2(&rn,
"xX")) hex = 1;
487 if (
test2(&rn, decp))
489 if (count > 0 &&
test2(&rn, (hex ?
"pP" :
"eE"))) {
495 rn.
buff[rn.
n] =
'\0';
525 }
while (c != EOF && c !=
'\n');
526 if (!chop && c ==
'\n')
553 nr = fread(p,
sizeof(
char), n, f);
572 for (n = first; nargs-- &&
success; n++) {
628 return luaL_error(L,
"file is already closed");
631 for (i = 1; i <= n; i++)
657 for (; nargs--; arg++) {
665 status = status && (len > 0);
670 status = status && (fwrite(s,
sizeof(
char), l, f) == l);
673 if (status)
return 1;
691 static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
692 static const char *
const modenames[] = {
"set",
"cur",
"end", NULL};
698 "not an integer in proper range");
699 op =
l_fseek(f, offset, mode[op]);
710 static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
711 static const char *
const modenames[] = {
"no",
"full",
"line", NULL};
715 int res = setvbuf(f, NULL, mode[op], (
size_t)sz);
#define luaL_addsize(B, s)
#define lua_isnoneornil(L, n)
static int f_read(lua_State *L)
static int io_tmpfile(lua_State *L)
LUA_API int lua_isinteger(lua_State *L, int idx)
static void aux_lines(lua_State *L, int toclose)
LUALIB_API int luaL_checkoption(lua_State *L, int arg, const char *def, const char *const lst[])
LUA_API void lua_pushnil(lua_State *L)
static int read_number(lua_State *L, FILE *f)
static int f_lines(lua_State *L)
static int io_lines(lua_State *L)
static int test_eof(lua_State *L, FILE *f)
static void createmeta(lua_State *L)
LUA_API int lua_toboolean(lua_State *L, int idx)
static int io_type(lua_State *L)
static int io_fclose(lua_State *L)
LUA_API void * lua_touserdata(lua_State *L, int idx)
static int io_read(lua_State *L)
static int g_iofile(lua_State *L, const char *f, const char *mode)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
static int read_chars(lua_State *L, FILE *f, size_t n)
#define lua_tointeger(L, i)
#define lua_tonumber(L, i)
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
static int read_line(lua_State *L, FILE *f, int chop)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
LUAMOD_API int luaopen_io(lua_State *L)
static int f_gc(lua_State *L)
#define luaL_newlibtable(L, l)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUALIB_API int luaL_execresult(lua_State *L, int stat)
static LStream * newprefile(lua_State *L)
static int f_seek(lua_State *L)
LUA_API void lua_settop(lua_State *L, int idx)
#define lua_upvalueindex(i)
static void read_all(lua_State *L, FILE *f)
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
int(* lua_CFunction)(lua_State *L)
static int io_readline(lua_State *L)
LUALIB_API const char * luaL_checklstring(lua_State *L, int arg, size_t *len)
static int io_close(lua_State *L)
static int io_popen(lua_State *L)
static int io_write(lua_State *L)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUA_API void lua_pushboolean(lua_State *L, int b)
static int g_write(lua_State *L, FILE *f, int arg)
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
static int f_flush(lua_State *L)
static int test2(RN *rn, const char *set)
static int io_noclose(lua_State *L)
static int io_flush(lua_State *L)
#define luaL_addchar(B, c)
#define lua_pushliteral(L, s)
LUA_API size_t lua_stringtonumber(lua_State *L, const char *s)
LUALIB_API void luaL_checkany(lua_State *L, int arg)
static void opencheck(lua_State *L, const char *fname, const char *mode)
#define luaL_prepbuffer(B)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
#define lua_getlocaledecpoint()
static int f_setvbuf(lua_State *L)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int arg)
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
LUA_API void * lua_newuserdatauv(lua_State *L, size_t size, int nuvalue)
LUA_API int lua_type(lua_State *L, int idx)
LUALIB_API int luaL_argerror(lua_State *L, int arg, const char *extramsg)
static const luaL_Reg iolib[]
static const luaL_Reg meth[]
#define lua_replace(L, idx)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int arg, lua_Integer def)
#define lua_tostring(L, i)
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
static const luaL_Reg metameth[]
static int f_close(lua_State *L)
#define luaL_newlib(L, l)
LUA_API void lua_rotate(lua_State *L, int idx, int n)
#define luaL_argcheck(L, cond, arg, extramsg)
static LStream * newfile(lua_State *L)
static int readdigits(RN *rn, int hex)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
#define LUA_REGISTRYINDEX
static int f_write(lua_State *L)
static int aux_close(lua_State *L)
LUALIB_API void luaL_setmetatable(lua_State *L, const char *tname)
#define l_pclose(L, file)
static int f_tostring(lua_State *L)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
static FILE * tofile(lua_State *L)
static int l_checkmode(const char *mode)
static int io_input(lua_State *L)
LUALIB_API char * luaL_prepbuffsize(luaL_Buffer *B, size_t sz)
static int g_read(lua_State *L, FILE *f, int first)
LUA_API int lua_getfield(lua_State *L, int idx, const char *k)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
static int io_open(lua_State *L)
#define luaL_optstring(L, n, d)
static int io_output(lua_State *L)
static int io_pclose(lua_State *L)
static FILE * getiofile(lua_State *L, const char *findex)
static void createstdfile(lua_State *L, FILE *f, const char *k, const char *fname)
LUA_API int lua_gettop(lua_State *L)
LUA_API lua_Unsigned lua_rawlen(lua_State *L, int idx)
#define luaL_checkstring(L, n)