Changeset View
Changeset View
Standalone View
Standalone View
contrib/lua/src/liolib.c
/* | /* | ||||
** $Id: liolib.c,v 2.151 2016/12/20 18:37:00 roberto Exp $ | ** $Id: liolib.c,v 2.151.1.1 2017/04/19 17:29:57 roberto Exp $ | ||||
** Standard I/O (and system) library | ** Standard I/O (and system) library | ||||
** See Copyright Notice in lua.h | ** See Copyright Notice in lua.h | ||||
*/ | */ | ||||
#define liolib_c | #define liolib_c | ||||
#define LUA_LIB | #define LUA_LIB | ||||
#include "lprefix.h" | #include "lprefix.h" | ||||
▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | |||||
static int aux_close (lua_State *L) { | static int aux_close (lua_State *L) { | ||||
LStream *p = tolstream(L); | LStream *p = tolstream(L); | ||||
volatile lua_CFunction cf = p->closef; | volatile lua_CFunction cf = p->closef; | ||||
p->closef = NULL; /* mark stream as closed */ | p->closef = NULL; /* mark stream as closed */ | ||||
return (*cf)(L); /* close it */ | return (*cf)(L); /* close it */ | ||||
} | } | ||||
static int f_close (lua_State *L) { | |||||
tofile(L); /* make sure argument is an open stream */ | |||||
return aux_close(L); | |||||
} | |||||
static int io_close (lua_State *L) { | static int io_close (lua_State *L) { | ||||
if (lua_isnone(L, 1)) /* no argument? */ | if (lua_isnone(L, 1)) /* no argument? */ | ||||
lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */ | lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */ | ||||
tofile(L); /* make sure argument is an open stream */ | return f_close(L); | ||||
return aux_close(L); | |||||
} | } | ||||
static int f_gc (lua_State *L) { | static int f_gc (lua_State *L) { | ||||
LStream *p = tolstream(L); | LStream *p = tolstream(L); | ||||
if (!isclosed(p) && p->f != NULL) | if (!isclosed(p) && p->f != NULL) | ||||
aux_close(L); /* ignore closed and incompletely open files */ | aux_close(L); /* ignore closed and incompletely open files */ | ||||
return 0; | return 0; | ||||
▲ Show 20 Lines • Show All 485 Lines • ▼ Show 20 Lines | static const luaL_Reg iolib[] = { | ||||
{NULL, NULL} | {NULL, NULL} | ||||
}; | }; | ||||
/* | /* | ||||
** methods for file handles | ** methods for file handles | ||||
*/ | */ | ||||
static const luaL_Reg flib[] = { | static const luaL_Reg flib[] = { | ||||
{"close", io_close}, | {"close", f_close}, | ||||
{"flush", f_flush}, | {"flush", f_flush}, | ||||
{"lines", f_lines}, | {"lines", f_lines}, | ||||
{"read", f_read}, | {"read", f_read}, | ||||
{"seek", f_seek}, | {"seek", f_seek}, | ||||
{"setvbuf", f_setvbuf}, | {"setvbuf", f_setvbuf}, | ||||
{"write", f_write}, | {"write", f_write}, | ||||
{"__gc", f_gc}, | {"__gc", f_gc}, | ||||
{"__tostring", f_tostring}, | {"__tostring", f_tostring}, | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |