The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Macros | Typedefs | Functions | Variables
liolib.cpp File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
Include dependency graph for liolib.cpp:

Go to the source code of this file.

Macros

#define _LARGEFILE_SOURCE   1
 
#define _FILE_OFFSET_BITS   64
 
#define liolib_c
 
#define LUA_LIB
 
#define lua_checkmode(mode)
 
#define lua_popen(L, c, m)
 
#define lua_pclose(L, file)   ((void)((void)L, file), -1)
 
#define l_fseek(f, o, w)   fseek(f,o,w)
 
#define l_ftell(f)   ftell(f)
 
#define l_seeknum   long
 
#define IO_PREFIX   "_IO_"
 
#define IO_INPUT   (IO_PREFIX "input")
 
#define IO_OUTPUT   (IO_PREFIX "output")
 
#define tolstream(L)   ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
 
#define isclosed(p)   ((p)->closef == NULL)
 
#define MAX_SIZE_T   (~(size_t)0)
 

Typedefs

typedef luaL_Stream LStream
 

Functions

static int io_type (lua_State *L)
 
static int f_tostring (lua_State *L)
 
static FILE * tofile (lua_State *L)
 
static LStreamnewprefile (lua_State *L)
 
static int aux_close (lua_State *L)
 
static int io_close (lua_State *L)
 
static int f_gc (lua_State *L)
 
static int io_fclose (lua_State *L)
 
static LStreamnewfile (lua_State *L)
 
static void opencheck (lua_State *L, const char *fname, const char *mode)
 
static int io_open (lua_State *L)
 
static int io_pclose (lua_State *L)
 
static int io_popen (lua_State *L)
 
static int io_tmpfile (lua_State *L)
 
static FILE * getiofile (lua_State *L, const char *findex)
 
static int g_iofile (lua_State *L, const char *f, const char *mode)
 
static int io_input (lua_State *L)
 
static int io_output (lua_State *L)
 
static int io_readline (lua_State *L)
 
static void aux_lines (lua_State *L, int toclose)
 
static int f_lines (lua_State *L)
 
static int io_lines (lua_State *L)
 
static int read_number (lua_State *L, FILE *f)
 
static int test_eof (lua_State *L, FILE *f)
 
static int read_line (lua_State *L, FILE *f, int chop)
 
static void read_all (lua_State *L, FILE *f)
 
static int read_chars (lua_State *L, FILE *f, size_t n)
 
static int g_read (lua_State *L, FILE *f, int first)
 
static int io_read (lua_State *L)
 
static int f_read (lua_State *L)
 
static int g_write (lua_State *L, FILE *f, int arg)
 
static int io_write (lua_State *L)
 
static int f_write (lua_State *L)
 
static int f_seek (lua_State *L)
 
static int f_setvbuf (lua_State *L)
 
static int io_flush (lua_State *L)
 
static int f_flush (lua_State *L)
 
static void createmeta (lua_State *L)
 
static int io_noclose (lua_State *L)
 
static void createstdfile (lua_State *L, FILE *f, const char *k, const char *fname)
 
LUAMOD_API int luaopen_io (lua_State *L)
 

Variables

static const luaL_Reg iolib []
 
static const luaL_Reg flib []
 

Macro Definition Documentation

#define _FILE_OFFSET_BITS   64

Definition at line 13 of file liolib.cpp.

#define _LARGEFILE_SOURCE   1

Definition at line 12 of file liolib.cpp.

#define IO_INPUT   (IO_PREFIX "input")

Definition at line 117 of file liolib.cpp.

Referenced by io_input(), io_lines(), io_read(), and luaopen_io().

#define IO_OUTPUT   (IO_PREFIX "output")

Definition at line 118 of file liolib.cpp.

Referenced by io_close(), io_flush(), io_output(), io_write(), and luaopen_io().

#define IO_PREFIX   "_IO_"

Definition at line 116 of file liolib.cpp.

Referenced by getiofile().

#define isclosed (   p)    ((p)->closef == NULL)

Definition at line 126 of file liolib.cpp.

Referenced by f_gc(), f_tostring(), getiofile(), io_readline(), io_type(), and tofile().

#define l_fseek (   f,
  o,
  w 
)    fseek(f,o,w)

Definition at line 108 of file liolib.cpp.

Referenced by f_seek().

#define l_ftell (   f)    ftell(f)

Definition at line 109 of file liolib.cpp.

Referenced by f_seek().

#define l_seeknum   long

Definition at line 110 of file liolib.cpp.

Referenced by f_seek().

#define liolib_c

Definition at line 22 of file liolib.cpp.

#define lua_checkmode (   mode)
Value:
(*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
(*mode != '+' || ++mode) && /* skip if char is '+' */ \
(*mode != 'b' || ++mode) && /* skip if char is 'b' */ \
(*mode == '\0'))
GLenum mode
Definition: glew.h:2390

Definition at line 38 of file liolib.cpp.

Referenced by io_open().

#define LUA_LIB

Definition at line 23 of file liolib.cpp.

#define lua_pclose (   L,
  file 
)    ((void)((void)L, file), -1)

Definition at line 70 of file liolib.cpp.

Referenced by io_pclose().

#define lua_popen (   L,
  c,
  m 
)
Value:
((void)((void)c, m), \
luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
#define LUA_QL(x)
Definition: luaconf.h:198
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
Definition: lauxlib.cpp:198
const GLdouble * m
Definition: glew.h:6968
#define c
Definition: glew.h:12743

Definition at line 68 of file liolib.cpp.

Referenced by io_popen().

#define MAX_SIZE_T   (~(size_t)0)

Definition at line 392 of file liolib.cpp.

Referenced by read_all().

#define tolstream (   L)    ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))

Definition at line 124 of file liolib.cpp.

Referenced by aux_close(), f_gc(), f_tostring(), io_fclose(), io_noclose(), io_pclose(), and tofile().

Typedef Documentation

Definition at line 121 of file liolib.cpp.

Function Documentation

static int aux_close ( lua_State L)
static

Definition at line 175 of file liolib.cpp.

References luaL_Stream::closef, and tolstream.

Referenced by f_gc(), io_close(), and io_readline().

static void aux_lines ( lua_State L,
int  toclose 
)
static
static void createmeta ( lua_State L)
static

Definition at line 622 of file liolib.cpp.

References LUA_FILEHANDLE, lua_pop, lua_pushvalue(), lua_setfield(), luaL_newmetatable(), and luaL_setfuncs().

Referenced by luaopen_io().

static void createstdfile ( lua_State L,
FILE *  f,
const char *  k,
const char *  fname 
)
static
static int f_flush ( lua_State L)
static

Definition at line 581 of file liolib.cpp.

References luaL_fileresult(), and tofile().

static int f_gc ( lua_State L)
static

Definition at line 191 of file liolib.cpp.

References aux_close(), luaL_Stream::f, isclosed, and tolstream.

static int f_lines ( lua_State L)
static

Definition at line 315 of file liolib.cpp.

References aux_lines(), and tofile().

static int f_read ( lua_State L)
static

Definition at line 478 of file liolib.cpp.

References g_read(), and tofile().

static int f_seek ( lua_State L)
static
static int f_setvbuf ( lua_State L)
static
static int f_tostring ( lua_State L)
static

Definition at line 143 of file liolib.cpp.

References luaL_Stream::f, isclosed, lua_pushfstring(), lua_pushliteral, and tolstream.

static int f_write ( lua_State L)
static

Definition at line 538 of file liolib.cpp.

References g_write(), lua_pushvalue(), and tofile().

static int g_iofile ( lua_State L,
const char *  f,
const char *  mode 
)
static
static int g_read ( lua_State L,
FILE *  f,
int  first 
)
static
static int g_write ( lua_State L,
FILE *  f,
int  arg 
)
static
static FILE* getiofile ( lua_State L,
const char *  findex 
)
static
static int io_close ( lua_State L)
static

Definition at line 183 of file liolib.cpp.

References aux_close(), IO_OUTPUT, lua_getfield(), lua_isnone, LUA_REGISTRYINDEX, and tofile().

static int io_fclose ( lua_State L)
static

Definition at line 202 of file liolib.cpp.

References luaL_Stream::f, luaL_fileresult(), and tolstream.

Referenced by newfile().

static int io_flush ( lua_State L)
static

Definition at line 576 of file liolib.cpp.

References getiofile(), IO_OUTPUT, and luaL_fileresult().

static int io_input ( lua_State L)
static

Definition at line 289 of file liolib.cpp.

References g_iofile(), and IO_INPUT.

static int io_lines ( lua_State L)
static
static int io_noclose ( lua_State L)
static

Definition at line 634 of file liolib.cpp.

References luaL_Stream::closef, lua_pushliteral, lua_pushnil(), and tolstream.

Referenced by createstdfile().

static int io_open ( lua_State L)
static
static int io_output ( lua_State L)
static

Definition at line 294 of file liolib.cpp.

References g_iofile(), and IO_OUTPUT.

static int io_pclose ( lua_State L)
static

Definition at line 239 of file liolib.cpp.

References luaL_Stream::f, lua_pclose, luaL_execresult(), and tolstream.

Referenced by io_popen().

static int io_popen ( lua_State L)
static
static int io_read ( lua_State L)
static

Definition at line 473 of file liolib.cpp.

References g_read(), getiofile(), and IO_INPUT.

static int io_readline ( lua_State L)
static
static int io_tmpfile ( lua_State L)
static

Definition at line 255 of file liolib.cpp.

References luaL_Stream::f, luaL_fileresult(), and newfile().

static int io_type ( lua_State L)
static
static int io_write ( lua_State L)
static

Definition at line 533 of file liolib.cpp.

References g_write(), getiofile(), and IO_OUTPUT.

LUAMOD_API int luaopen_io ( lua_State L)

Definition at line 656 of file liolib.cpp.

References createmeta(), createstdfile(), IO_INPUT, IO_OUTPUT, and luaL_newlib.

static LStream* newfile ( lua_State L)
static

Definition at line 209 of file liolib.cpp.

References luaL_Stream::closef, luaL_Stream::f, io_fclose(), and newprefile().

Referenced by io_open(), io_tmpfile(), and opencheck().

static LStream* newprefile ( lua_State L)
static

Definition at line 167 of file liolib.cpp.

References luaL_Stream::closef, LUA_FILEHANDLE, lua_newuserdata(), and luaL_setmetatable().

Referenced by createstdfile(), io_popen(), and newfile().

static void opencheck ( lua_State L,
const char *  fname,
const char *  mode 
)
static

Definition at line 217 of file liolib.cpp.

References luaL_Stream::f, LUA_QS, luaL_error(), and newfile().

Referenced by g_iofile(), and io_lines().

static void read_all ( lua_State L,
FILE *  f 
)
static

Definition at line 394 of file liolib.cpp.

References luaL_addsize, LUAL_BUFFERSIZE, luaL_buffinit(), luaL_prepbuffsize(), luaL_pushresult(), and MAX_SIZE_T.

Referenced by g_read().

static int read_chars ( lua_State L,
FILE *  f,
size_t  n 
)
static

Definition at line 410 of file liolib.cpp.

References luaL_addsize, luaL_buffinit(), luaL_prepbuffsize(), and luaL_pushresult().

Referenced by g_read().

static int read_line ( lua_State L,
FILE *  f,
int  chop 
)
static

Definition at line 370 of file liolib.cpp.

References lua_rawlen(), luaL_addsize, LUAL_BUFFERSIZE, luaL_buffinit(), luaL_prepbuffer, and luaL_pushresult().

Referenced by g_read().

static int read_number ( lua_State L,
FILE *  f 
)
static

Definition at line 349 of file liolib.cpp.

References d, LUA_NUMBER_SCAN, lua_pushnil(), and lua_pushnumber().

Referenced by g_read().

static int test_eof ( lua_State L,
FILE *  f 
)
static

Definition at line 362 of file liolib.cpp.

References lua_pushlstring().

Referenced by g_read().

static FILE* tofile ( lua_State L)
static

Variable Documentation

const luaL_Reg flib[]
static
Initial value:
= {
{"close", io_close},
{"flush", f_flush},
{"lines", f_lines},
{"read", f_read},
{"seek", f_seek},
{"setvbuf", f_setvbuf},
{"write", f_write},
{"__gc", f_gc},
{"__tostring", f_tostring},
{NULL, NULL}
}
static int f_seek(lua_State *L)
Definition: liolib.cpp:545
static int io_close(lua_State *L)
Definition: liolib.cpp:183
static int f_setvbuf(lua_State *L)
Definition: liolib.cpp:564
static int f_flush(lua_State *L)
Definition: liolib.cpp:581
static int f_read(lua_State *L)
Definition: liolib.cpp:478
static int f_write(lua_State *L)
Definition: liolib.cpp:538
static int f_tostring(lua_State *L)
Definition: liolib.cpp:143
static int f_gc(lua_State *L)
Definition: liolib.cpp:191
static int f_lines(lua_State *L)
Definition: liolib.cpp:315

Definition at line 608 of file liolib.cpp.

const luaL_Reg iolib[]
static
Initial value:
= {
{"close", io_close},
{"flush", io_flush},
{"input", io_input},
{"lines", io_lines},
{"open", io_open},
{"output", io_output},
{"popen", io_popen},
{"read", io_read},
{"tmpfile", io_tmpfile},
{"type", io_type},
{"write", io_write},
{NULL, NULL}
}
static int io_input(lua_State *L)
Definition: liolib.cpp:289
static int io_close(lua_State *L)
Definition: liolib.cpp:183
static int io_popen(lua_State *L)
Definition: liolib.cpp:245
static int io_output(lua_State *L)
Definition: liolib.cpp:294
static int io_type(lua_State *L)
Definition: liolib.cpp:129
static int io_open(lua_State *L)
Definition: liolib.cpp:225
static int io_tmpfile(lua_State *L)
Definition: liolib.cpp:255
static int io_lines(lua_State *L)
Definition: liolib.cpp:322
static int io_flush(lua_State *L)
Definition: liolib.cpp:576
static int io_read(lua_State *L)
Definition: liolib.cpp:473
static int io_write(lua_State *L)
Definition: liolib.cpp:533

Definition at line 589 of file liolib.cpp.