mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
simplifications.
This commit is contained in:
parent
521b38532a
commit
88b65da4d7
27
liolib.c
27
liolib.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: liolib.c,v 1.39 1999/05/05 19:22:26 roberto Exp roberto $
|
** $Id: liolib.c,v 1.40 1999/05/14 12:24:04 roberto Exp roberto $
|
||||||
** Standard I/O (and system) library
|
** Standard I/O (and system) library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -157,9 +157,13 @@ static void setfile (FILE *f, char *name, int tag) {
|
|||||||
|
|
||||||
|
|
||||||
static void setreturn (FILE *f, char *name) {
|
static void setreturn (FILE *f, char *name) {
|
||||||
int tag = gettag();
|
if (f == NULL)
|
||||||
setfile(f, name, tag);
|
pushresult(0);
|
||||||
lua_pushusertag(f, tag);
|
else {
|
||||||
|
int tag = gettag();
|
||||||
|
setfile(f, name, tag);
|
||||||
|
lua_pushusertag(f, tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -175,10 +179,6 @@ static void io_readfrom (void) {
|
|||||||
else {
|
else {
|
||||||
char *s = luaL_check_string(FIRSTARG);
|
char *s = luaL_check_string(FIRSTARG);
|
||||||
current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
|
current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
|
||||||
if (current == NULL) {
|
|
||||||
pushresult(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setreturn(current, FINPUT);
|
setreturn(current, FINPUT);
|
||||||
}
|
}
|
||||||
@ -196,21 +196,14 @@ static void io_writeto (void) {
|
|||||||
else {
|
else {
|
||||||
char *s = luaL_check_string(FIRSTARG);
|
char *s = luaL_check_string(FIRSTARG);
|
||||||
current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w");
|
current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w");
|
||||||
if (current == NULL) {
|
|
||||||
pushresult(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setreturn(current, FOUTPUT);
|
setreturn(current, FOUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void io_appendto (void) {
|
static void io_appendto (void) {
|
||||||
FILE *fp = fopen(luaL_check_string(FIRSTARG), "a");
|
FILE *current = fopen(luaL_check_string(FIRSTARG), "a");
|
||||||
if (fp != NULL)
|
setreturn(current, FOUTPUT);
|
||||||
setreturn(fp, FOUTPUT);
|
|
||||||
else
|
|
||||||
pushresult(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user