Defines | Typedefs | Functions | Variables

lua/liolib.c 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.c:

Go to the source code of this file.

Defines

#define _FILE_OFFSET_BITS   64
#define liolib_c
#define LUA_LIB
#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 []

Define Documentation

#define _FILE_OFFSET_BITS   64

Definition at line 14 of file liolib.c.

#define IO_INPUT   (IO_PREFIX "input")

Definition at line 103 of file liolib.c.

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

#define IO_OUTPUT   (IO_PREFIX "output")

Definition at line 104 of file liolib.c.

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

#define IO_PREFIX   "_IO_"

Definition at line 102 of file liolib.c.

Referenced by getiofile().

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

Definition at line 112 of file liolib.c.

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 91 of file liolib.c.

Referenced by f_seek().

#define l_ftell (   f  )     ftell(f)

Definition at line 92 of file liolib.c.

Referenced by f_seek().

#define l_seeknum   long

Definition at line 93 of file liolib.c.

Referenced by f_seek().

#define liolib_c

Definition at line 23 of file liolib.c.

#define LUA_LIB

Definition at line 24 of file liolib.c.

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

Definition at line 57 of file liolib.c.

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)

Definition at line 55 of file liolib.c.

Referenced by io_popen().

#define MAX_SIZE_T   (~(size_t)0)

Definition at line 384 of file liolib.c.

Referenced by read_all().

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

Definition at line 110 of file liolib.c.

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


Typedef Documentation

Definition at line 107 of file liolib.c.


Function Documentation

static int aux_close ( lua_State L  )  [static]

Definition at line 161 of file liolib.c.

References luaL_Stream::closef, and tolstream.

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

Here is the caller graph for this function:

static void aux_lines ( lua_State L,
int  toclose 
) [static]

Definition at line 294 of file liolib.c.

References io_readline(), lua_gettop(), LUA_MINSTACK, lua_pushboolean(), lua_pushcclosure(), lua_pushinteger(), lua_pushvalue(), and luaL_argcheck.

Referenced by f_lines(), and io_lines().

Here is the call graph for this function:

Here is the caller graph for this function:

static void createmeta ( lua_State L  )  [static]

Definition at line 614 of file liolib.c.

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

Referenced by luaopen_io().

Here is the call graph for this function:

Here is the caller graph for this function:

static void createstdfile ( lua_State L,
FILE *  f,
const char *  k,
const char *  fname 
) [static]

Definition at line 635 of file liolib.c.

References luaL_Stream::closef, luaL_Stream::f, lua_pushvalue(), LUA_REGISTRYINDEX, lua_setfield(), and newprefile().

Referenced by luaopen_io().

Here is the call graph for this function:

Here is the caller graph for this function:

static int f_flush ( lua_State L  )  [static]

Definition at line 573 of file liolib.c.

References luaL_fileresult(), and tofile().

Here is the call graph for this function:

static int f_gc ( lua_State L  )  [static]

Definition at line 177 of file liolib.c.

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

Here is the call graph for this function:

static int f_lines ( lua_State L  )  [static]

Definition at line 307 of file liolib.c.

References aux_lines(), and tofile().

Here is the call graph for this function:

static int f_read ( lua_State L  )  [static]

Definition at line 470 of file liolib.c.

References g_read(), and tofile().

Here is the call graph for this function:

static int f_seek ( lua_State L  )  [static]

Definition at line 537 of file liolib.c.

References l_fseek, l_ftell, l_seeknum, lua_pushnumber(), luaL_argcheck, luaL_checkoption(), luaL_fileresult(), luaL_optnumber(), and tofile().

Here is the call graph for this function:

static int f_setvbuf ( lua_State L  )  [static]

Definition at line 556 of file liolib.c.

References LUAL_BUFFERSIZE, luaL_checkoption(), luaL_fileresult(), luaL_optinteger(), and tofile().

Here is the call graph for this function:

static int f_tostring ( lua_State L  )  [static]

Definition at line 129 of file liolib.c.

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

Here is the call graph for this function:

static int f_write ( lua_State L  )  [static]

Definition at line 530 of file liolib.c.

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

Here is the call graph for this function:

static int g_iofile ( lua_State L,
const char *  f,
const char *  mode 
) [static]

Definition at line 264 of file liolib.c.

References lua_getfield(), lua_isnoneornil, lua_pushvalue(), LUA_REGISTRYINDEX, lua_setfield(), lua_tostring, opencheck(), and tofile().

Referenced by io_input(), and io_output().

Here is the call graph for this function:

Here is the caller graph for this function:

static int g_read ( lua_State L,
FILE *  f,
int  first 
) [static]

Definition at line 415 of file liolib.c.

References lua_gettop(), LUA_MINSTACK, lua_pop, lua_pushnil(), LUA_TNUMBER, lua_tointeger, lua_tostring, lua_type(), luaL_argcheck, luaL_argerror(), luaL_checkstack(), luaL_fileresult(), read_all(), read_chars(), read_line(), read_number(), and test_eof().

Referenced by f_read(), io_read(), and io_readline().

Here is the call graph for this function:

Here is the caller graph for this function:

static int g_write ( lua_State L,
FILE *  f,
int  arg 
) [static]

Definition at line 505 of file liolib.c.

References lua_gettop(), LUA_NUMBER_FMT, LUA_TNUMBER, lua_tonumber, lua_type(), luaL_checklstring(), and luaL_fileresult().

Referenced by f_write(), and io_write().

Here is the call graph for this function:

Here is the caller graph for this function:

static FILE* getiofile ( lua_State L,
const char *  findex 
) [static]

Definition at line 254 of file liolib.c.

References luaL_Stream::f, IO_PREFIX, isclosed, lua_getfield(), LUA_REGISTRYINDEX, lua_touserdata(), and luaL_error().

Referenced by io_flush(), io_read(), and io_write().

Here is the call graph for this function:

Here is the caller graph for this function:

static int io_close ( lua_State L  )  [static]

Definition at line 169 of file liolib.c.

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

Here is the call graph for this function:

static int io_fclose ( lua_State L  )  [static]

Definition at line 188 of file liolib.c.

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

Here is the call graph for this function:

static int io_flush ( lua_State L  )  [static]

Definition at line 568 of file liolib.c.

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

Here is the call graph for this function:

static int io_input ( lua_State L  )  [static]

Definition at line 281 of file liolib.c.

References g_iofile(), and IO_INPUT.

Here is the call graph for this function:

static int io_lines ( lua_State L  )  [static]

Definition at line 314 of file liolib.c.

References aux_lines(), IO_INPUT, lua_getfield(), lua_isnil, lua_isnone, lua_pushnil(), LUA_REGISTRYINDEX, lua_replace(), luaL_checkstring, opencheck(), and tofile().

Here is the call graph for this function:

static int io_noclose ( lua_State L  )  [static]

Definition at line 626 of file liolib.c.

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

Here is the call graph for this function:

static int io_open ( lua_State L  )  [static]

Definition at line 211 of file liolib.c.

References luaL_Stream::f, LUA_QL, LUA_QS, luaL_checkstring, luaL_error(), luaL_fileresult(), luaL_optstring, and newfile().

Here is the call graph for this function:

static int io_output ( lua_State L  )  [static]

Definition at line 286 of file liolib.c.

References g_iofile(), and IO_OUTPUT.

Here is the call graph for this function:

static int io_pclose ( lua_State L  )  [static]

Definition at line 231 of file liolib.c.

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

Here is the call graph for this function:

static int io_popen ( lua_State L  )  [static]

Definition at line 237 of file liolib.c.

References luaL_Stream::closef, luaL_Stream::f, lua_popen, luaL_checkstring, luaL_fileresult(), luaL_optstring, and newprefile().

Here is the call graph for this function:

static int io_read ( lua_State L  )  [static]

Definition at line 465 of file liolib.c.

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

Here is the call graph for this function:

static int io_readline ( lua_State L  )  [static]

Definition at line 475 of file liolib.c.

References aux_close(), luaL_Stream::f, g_read(), isclosed, lua_assert, lua_isnil, lua_pushvalue(), lua_settop(), lua_toboolean(), lua_tointeger, lua_tostring, lua_touserdata(), lua_upvalueindex, and luaL_error().

Referenced by aux_lines().

Here is the call graph for this function:

Here is the caller graph for this function:

static int io_tmpfile ( lua_State L  )  [static]

Definition at line 247 of file liolib.c.

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

Here is the call graph for this function:

static int io_type ( lua_State L  )  [static]

Definition at line 115 of file liolib.c.

References isclosed, LUA_FILEHANDLE, lua_pushliteral, lua_pushnil(), luaL_checkany(), and luaL_testudata().

Here is the call graph for this function:

static int io_write ( lua_State L  )  [static]

Definition at line 525 of file liolib.c.

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

Here is the call graph for this function:

LUAMOD_API int luaopen_io ( lua_State L  ) 

Definition at line 648 of file liolib.c.

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

Here is the call graph for this function:

static LStream* newfile ( lua_State L  )  [static]

Definition at line 195 of file liolib.c.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

static LStream* newprefile ( lua_State L  )  [static]

Definition at line 153 of file liolib.c.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 203 of file liolib.c.

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

Referenced by g_iofile(), and io_lines().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 386 of file liolib.c.

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

Referenced by g_read().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 402 of file liolib.c.

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

Referenced by g_read().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 362 of file liolib.c.

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

Referenced by g_read().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 341 of file liolib.c.

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

Referenced by g_read().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 354 of file liolib.c.

References lua_pushlstring().

Referenced by g_read().

Here is the call graph for this function:

Here is the caller graph for this function:

static FILE* tofile ( lua_State L  )  [static]

Definition at line 139 of file liolib.c.

References luaL_Stream::f, isclosed, lua_assert, luaL_error(), and tolstream.

Referenced by f_flush(), f_lines(), f_read(), f_seek(), f_setvbuf(), f_write(), g_iofile(), io_close(), and io_lines().

Here is the call graph for this function:

Here is the caller graph for this function:


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}
}

Definition at line 600 of file liolib.c.

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}
}

Definition at line 581 of file liolib.c.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:07:09 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs