11 #if !defined(_FILE_OFFSET_BITS)
12 #define _LARGEFILE_SOURCE 1
13 #define _FILE_OFFSET_BITS 64
31 #if !defined(lua_checkmode)
38 #define lua_checkmode(mode) \
39 (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
40 (*mode != '+' || ++mode) && \
41 (*mode != 'b' || ++mode) && \
53 #if !defined(lua_popen)
55 #if defined(LUA_USE_POPEN)
57 #define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
58 #define lua_pclose(L,file) ((void)L, pclose(file))
60 #elif defined(LUA_WIN)
62 #define lua_popen(L,c,m) ((void)L, _popen(c,m))
63 #define lua_pclose(L,file) ((void)L, _pclose(file))
68 #define lua_popen(L,c,m) ((void)((void)c, m), \
69 luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
70 #define lua_pclose(L,file) ((void)((void)L, file), -1)
86 #if !defined(lua_fseek) && !defined(LUA_ANSI)
88 #if defined(LUA_USE_POSIX)
90 #define l_fseek(f,o,w) fseeko(f,o,w)
91 #define l_ftell(f) ftello(f)
92 #define l_seeknum off_t
94 #elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \
95 && defined(_MSC_VER) && (_MSC_VER >= 1400)
98 #define l_fseek(f,o,w) _fseeki64(f,o,w)
99 #define l_ftell(f) _ftelli64(f)
100 #define l_seeknum __int64
107 #if !defined(l_fseek)
108 #define l_fseek(f,o,w) fseek(f,o,w)
109 #define l_ftell(f) ftell(f)
110 #define l_seeknum long
116 #define IO_PREFIX "_IO_"
117 #define IO_INPUT (IO_PREFIX "input")
118 #define IO_OUTPUT (IO_PREFIX "output")
124 #define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
126 #define isclosed(p) ((p)->closef == NULL)
156 luaL_error(L,
"attempt to use a closed file");
204 int res = fclose(p->
f);
219 p->
f = fopen(fname, mode);
229 const char *md =
mode;
231 p->
f = fopen(filename, mode);
381 if (l == 0 || p[l-1] !=
'\n')
392 #define MAX_SIZE_T (~(size_t)0)
400 size_t nr = fread(p,
sizeof(
char), rlen, f);
402 if (nr < rlen)
break;
416 nr = fread(p,
sizeof(
char), n, f);
435 for (n = first; nargs-- && success; n++) {
488 return luaL_error(L,
"file is already closed");
490 for (i = 1; i <=
n; i++)
516 for (; nargs--; arg++) {
525 status = status && (fwrite(s,
sizeof(
char), l, f) ==
l);
528 if (status)
return 1;
546 static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
547 static const char *
const modenames[] = {
"set",
"cur",
"end", NULL};
553 "not an integer in proper range");
554 op =
l_fseek(f, offset, mode[op]);
565 static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
566 static const char *
const modenames[] = {
"no",
"full",
"line", NULL};
570 int res = setvbuf(f, NULL, mode[op], sz);
#define luaL_addsize(B, s)
static int io_input(lua_State *L)
#define lua_isnoneornil(L, n)
static int f_seek(lua_State *L)
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
LUA_API void lua_replace(lua_State *L, int idx)
static int io_close(lua_State *L)
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API int lua_type(lua_State *L, int idx)
static void createmeta(lua_State *L)
LUALIB_API char * luaL_prepbuffsize(luaL_Buffer *B, size_t sz)
static int read_line(lua_State *L, FILE *f, int chop)
LUA_API void lua_pushboolean(lua_State *L, int b)
static void read_all(lua_State *L, FILE *f)
static int io_fclose(lua_State *L)
static FILE * tofile(lua_State *L)
static void createstdfile(lua_State *L, FILE *f, const char *k, const char *fname)
static int test_eof(lua_State *L, FILE *f)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
static int io_popen(lua_State *L)
LUA_API int lua_gettop(lua_State *L)
static int f_setvbuf(lua_State *L)
static int g_write(lua_State *L, FILE *f, int arg)
#define lua_tointeger(L, i)
static int g_read(lua_State *L, FILE *f, int first)
#define lua_tonumber(L, i)
static int f_flush(lua_State *L)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
LUALIB_API void luaL_setmetatable(lua_State *L, const char *tname)
#define luaL_argcheck(L, cond, numarg, extramsg)
static FILE * getiofile(lua_State *L, const char *findex)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
LUA_API void * lua_newuserdata(lua_State *L, size_t size)
int(* lua_CFunction)(lua_State *L)
#define lua_pclose(L, file)
static int aux_close(lua_State *L)
static int f_read(lua_State *L)
GLdouble GLdouble GLdouble b
#define lua_upvalueindex(i)
LUAMOD_API int luaopen_io(lua_State *L)
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
static int read_number(lua_State *L, FILE *f)
LUALIB_API int luaL_checkoption(lua_State *L, int narg, const char *def, const char *const lst[])
static int io_noclose(lua_State *L)
static int io_pclose(lua_State *L)
static int io_readline(lua_State *L)
LUA_API int lua_toboolean(lua_State *L, int idx)
static int read_chars(lua_State *L, FILE *f, size_t n)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
static int io_output(lua_State *L)
#define lua_checkmode(mode)
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
static int f_write(lua_State *L)
static LStream * newprefile(lua_State *L)
static const luaL_Reg iolib[]
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
LUA_API void lua_pushnil(lua_State *L)
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)
#define lua_pushliteral(L, s)
LUALIB_API lua_Number luaL_optnumber(lua_State *L, int narg, lua_Number def)
#define luaL_prepbuffer(B)
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
LUA_API void * lua_touserdata(lua_State *L, int idx)
static int f_tostring(lua_State *L)
static void aux_lines(lua_State *L, int toclose)
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
#define lua_tostring(L, i)
static int f_gc(lua_State *L)
LUA_API void lua_pushvalue(lua_State *L, int idx)
static int io_type(lua_State *L)
static int io_open(lua_State *L)
#define luaL_newlib(L, l)
static int io_tmpfile(lua_State *L)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
static int io_lines(lua_State *L)
LUA_API size_t lua_rawlen(lua_State *L, int idx)
static int io_flush(lua_State *L)
#define LUA_REGISTRYINDEX
#define lua_popen(L, c, m)
static int io_read(lua_State *L)
static LStream * newfile(lua_State *L)
static int f_lines(lua_State *L)
LUALIB_API void luaL_checkany(lua_State *L, int narg)
LUALIB_API int luaL_execresult(lua_State *L, int stat)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
#define luaL_optstring(L, n, d)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
static int g_iofile(lua_State *L, const char *f, const char *mode)
static const luaL_Reg flib[]
static void opencheck(lua_State *L, const char *fname, const char *mode)
static int io_write(lua_State *L)
#define luaL_checkstring(L, n)