The Battle for Wesnoth  1.15.1+dev
Classes | Macros | Typedefs | Functions | Variables
liolib.cpp File Reference
#include "lprefix.h"
#include <ctype.h>
#include <errno.h>
#include <locale.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.

Classes

struct  RN
 

Macros

#define liolib_c
 
#define LUA_LIB
 
#define L_MODEEXT   "b"
 
#define l_popen(L, c, m)
 
#define l_pclose(L, file)   ((void)L, (void)file, -1)
 
#define l_getc(f)   getc(f)
 
#define l_lockfile(f)   ((void)0)
 
#define l_unlockfile(f)   ((void)0)
 
#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 IOPREF_LEN   (sizeof(IO_PREFIX)/sizeof(char) - 1)
 
#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 MAXARGLINE   250
 
#define L_MAXLENNUM   200
 

Typedefs

typedef luaL_Stream LStream
 

Functions

static int l_checkmode (const char *mode)
 
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 f_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 nextc (RN *rn)
 
static int test2 (RN *rn, const char *set)
 
static int readdigits (RN *rn, int hex)
 
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

◆ IO_INPUT

#define IO_INPUT   (IO_PREFIX "input")

Definition at line 138 of file liolib.cpp.

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

◆ IO_OUTPUT

#define IO_OUTPUT   (IO_PREFIX "output")

Definition at line 139 of file liolib.cpp.

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

◆ IO_PREFIX

#define IO_PREFIX   "_IO_"

Definition at line 136 of file liolib.cpp.

◆ IOPREF_LEN

#define IOPREF_LEN   (sizeof(IO_PREFIX)/sizeof(char) - 1)

Definition at line 137 of file liolib.cpp.

Referenced by getiofile().

◆ isclosed

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

Definition at line 147 of file liolib.cpp.

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

◆ l_fseek

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

Definition at line 125 of file liolib.cpp.

Referenced by f_seek().

◆ l_ftell

#define l_ftell (   f)    ftell(f)

Definition at line 126 of file liolib.cpp.

Referenced by f_seek().

◆ l_getc

#define l_getc (   f)    getc(f)

Definition at line 90 of file liolib.cpp.

Referenced by nextc(), read_line(), and read_number().

◆ l_lockfile

#define l_lockfile (   f)    ((void)0)

Definition at line 91 of file liolib.cpp.

Referenced by read_line(), and read_number().

◆ L_MAXLENNUM

#define L_MAXLENNUM   200

Definition at line 385 of file liolib.cpp.

Referenced by nextc().

◆ L_MODEEXT

#define L_MODEEXT   "b"

Definition at line 36 of file liolib.cpp.

Referenced by l_checkmode().

◆ l_pclose

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

Definition at line 74 of file liolib.cpp.

Referenced by io_pclose().

◆ l_popen

#define l_popen (   L,
  c,
 
)
Value:
((void)((void)c, m), \
luaL_error(L, "'popen' not supported"), \
(FILE*)0)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
Definition: lauxlib.cpp:223
mock_char c

Definition at line 70 of file liolib.cpp.

Referenced by io_popen().

◆ l_seeknum

#define l_seeknum   long

Definition at line 127 of file liolib.cpp.

Referenced by f_seek().

◆ l_unlockfile

#define l_unlockfile (   f)    ((void)0)

Definition at line 92 of file liolib.cpp.

Referenced by read_line(), and read_number().

◆ liolib_c

#define liolib_c

Definition at line 7 of file liolib.cpp.

◆ LUA_LIB

#define LUA_LIB

Definition at line 8 of file liolib.cpp.

◆ MAXARGLINE

#define MAXARGLINE   250

Definition at line 337 of file liolib.cpp.

Referenced by aux_lines().

◆ tolstream

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

Definition at line 145 of file liolib.cpp.

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

Typedef Documentation

◆ LStream

Definition at line 142 of file liolib.cpp.

Function Documentation

◆ aux_close()

static int aux_close ( lua_State L)
static

Definition at line 201 of file liolib.cpp.

References luaL_Stream::closef, p, and tolstream.

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

◆ aux_lines()

static void aux_lines ( lua_State L,
int  toclose 
)
static

◆ createmeta()

static void createmeta ( lua_State L)
static

Definition at line 733 of file liolib.cpp.

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

Referenced by luaopen_io().

◆ createstdfile()

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

◆ f_close()

static int f_close ( lua_State L)
static

Definition at line 209 of file liolib.cpp.

References aux_close(), and tofile().

Referenced by io_close().

◆ f_flush()

static int f_flush ( lua_State L)
static

Definition at line 692 of file liolib.cpp.

References luaL_fileresult(), and tofile().

◆ f_gc()

static int f_gc ( lua_State L)
static

Definition at line 222 of file liolib.cpp.

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

◆ f_lines()

static int f_lines ( lua_State L)
static

Definition at line 349 of file liolib.cpp.

References aux_lines(), and tofile().

◆ f_read()

static int f_read ( lua_State L)
static

Definition at line 584 of file liolib.cpp.

References g_read(), and tofile().

◆ f_seek()

static int f_seek ( lua_State L)
static

◆ f_setvbuf()

static int f_setvbuf ( lua_State L)
static

◆ f_tostring()

static int f_tostring ( lua_State L)
static

Definition at line 164 of file liolib.cpp.

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

◆ f_write()

static int f_write ( lua_State L)
static

Definition at line 649 of file liolib.cpp.

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

◆ g_iofile()

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

◆ g_read()

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

◆ g_write()

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

◆ getiofile()

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

◆ io_close()

static int io_close ( lua_State L)
static

Definition at line 215 of file liolib.cpp.

References f_close(), IO_OUTPUT, lua_getfield(), lua_isnone, and LUA_REGISTRYINDEX.

◆ io_fclose()

static int io_fclose ( lua_State L)
static

Definition at line 233 of file liolib.cpp.

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

Referenced by newfile().

◆ io_flush()

static int io_flush ( lua_State L)
static

Definition at line 687 of file liolib.cpp.

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

◆ io_input()

static int io_input ( lua_State L)
static

Definition at line 320 of file liolib.cpp.

References g_iofile(), and IO_INPUT.

◆ io_lines()

static int io_lines ( lua_State L)
static

◆ io_noclose()

static int io_noclose ( lua_State L)
static

Definition at line 745 of file liolib.cpp.

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

Referenced by createstdfile().

◆ io_open()

static int io_open ( lua_State L)
static

◆ io_output()

static int io_output ( lua_State L)
static

Definition at line 325 of file liolib.cpp.

References g_iofile(), IO_OUTPUT, and io_readline().

◆ io_pclose()

static int io_pclose ( lua_State L)
static

Definition at line 270 of file liolib.cpp.

References luaL_Stream::f, l_pclose, luaL_execresult(), p, and tolstream.

Referenced by io_popen().

◆ io_popen()

static int io_popen ( lua_State L)
static

◆ io_read()

static int io_read ( lua_State L)
static

Definition at line 579 of file liolib.cpp.

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

◆ io_readline()

static int io_readline ( lua_State L)
static

◆ io_tmpfile()

static int io_tmpfile ( lua_State L)
static

Definition at line 286 of file liolib.cpp.

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

◆ io_type()

static int io_type ( lua_State L)
static

◆ io_write()

static int io_write ( lua_State L)
static

Definition at line 644 of file liolib.cpp.

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

◆ l_checkmode()

static int l_checkmode ( const char *  mode)
static

Definition at line 40 of file liolib.cpp.

References L_MODEEXT.

Referenced by io_open().

◆ luaopen_io()

LUAMOD_API int luaopen_io ( lua_State L)

Definition at line 767 of file liolib.cpp.

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

◆ newfile()

static LStream* newfile ( lua_State L)
static

Definition at line 240 of file liolib.cpp.

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

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

◆ newprefile()

static LStream* newprefile ( lua_State L)
static

Definition at line 188 of file liolib.cpp.

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

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

◆ nextc()

static int nextc ( RN rn)
static

Definition at line 401 of file liolib.cpp.

References RN::buff, RN::c, RN::f, l_getc, L_MAXLENNUM, and RN::n.

Referenced by readdigits(), and test2().

◆ opencheck()

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

Definition at line 248 of file liolib.cpp.

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

Referenced by g_iofile(), and io_lines().

◆ read_all()

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

Definition at line 503 of file liolib.cpp.

References b, luaL_addsize, LUAL_BUFFERSIZE, luaL_buffinit(), luaL_prepbuffer, luaL_pushresult(), and p.

Referenced by g_read().

◆ read_chars()

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

Definition at line 516 of file liolib.cpp.

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

Referenced by g_read().

◆ read_line()

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

◆ read_number()

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

◆ readdigits()

static int readdigits ( RN rn,
int  hex 
)
static

Definition at line 427 of file liolib.cpp.

References RN::c, and nextc().

Referenced by read_number().

◆ test2()

static int test2 ( RN rn,
const char *  set 
)
static

Definition at line 417 of file liolib.cpp.

References RN::c, and nextc().

Referenced by read_number().

◆ test_eof()

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

Definition at line 474 of file liolib.cpp.

References c, and lua_pushliteral.

Referenced by g_read().

◆ tofile()

static FILE* tofile ( lua_State L)
static

Variable Documentation

◆ flib

const luaL_Reg flib[]
static
Initial value:
= {
{"close", f_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:656
static int f_setvbuf(lua_State *L)
Definition: liolib.cpp:675
static int f_flush(lua_State *L)
Definition: liolib.cpp:692
static int f_read(lua_State *L)
Definition: liolib.cpp:584
static int f_write(lua_State *L)
Definition: liolib.cpp:649
static int f_tostring(lua_State *L)
Definition: liolib.cpp:164
static int f_gc(lua_State *L)
Definition: liolib.cpp:222
static int f_lines(lua_State *L)
Definition: liolib.cpp:349
static int f_close(lua_State *L)
Definition: liolib.cpp:209

Definition at line 719 of file liolib.cpp.

◆ iolib

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:320
static int io_close(lua_State *L)
Definition: liolib.cpp:215
static int io_popen(lua_State *L)
Definition: liolib.cpp:276
static int io_output(lua_State *L)
Definition: liolib.cpp:325
static int io_type(lua_State *L)
Definition: liolib.cpp:150
static int io_open(lua_State *L)
Definition: liolib.cpp:256
static int io_tmpfile(lua_State *L)
Definition: liolib.cpp:286
static int io_lines(lua_State *L)
Definition: liolib.cpp:356
static int io_flush(lua_State *L)
Definition: liolib.cpp:687
static int io_read(lua_State *L)
Definition: liolib.cpp:579
static int io_write(lua_State *L)
Definition: liolib.cpp:644

Definition at line 700 of file liolib.cpp.