"pushnil" is not needed (default return is nil).

This commit is contained in:
Roberto Ierusalimschy 1996-08-01 11:55:33 -03:00
parent cc02b4729b
commit f025b0d160
1 changed files with 6 additions and 23 deletions

29
iolib.c
View File

@ -3,7 +3,7 @@
** Input/output library to LUA ** Input/output library to LUA
*/ */
char *rcs_iolib="$Id: iolib.c,v 1.45 1996/05/22 21:59:07 roberto Exp roberto $"; char *rcs_iolib="$Id: iolib.c,v 1.46 1996/05/27 14:06:58 roberto Exp roberto $";
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
@ -32,8 +32,6 @@ static void pushresult (int i)
{ {
if (i) if (i)
lua_pushnumber (1); lua_pushnumber (1);
else
lua_pushnil();
} }
static void closeread (void) static void closeread (void)
@ -106,9 +104,7 @@ static void io_writeto (void)
{ {
char *s = lua_check_string(1, "writeto"); char *s = lua_check_string(1, "writeto");
FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w");
if (fp == NULL) if (fp)
lua_pushnil();
else
{ {
closewrite(); closewrite();
out = fp; out = fp;
@ -130,9 +126,7 @@ static void io_appendto (void)
{ {
char *s = lua_check_string(1, "appendto"); char *s = lua_check_string(1, "appendto");
FILE *fp = fopen (s, "a"); FILE *fp = fopen (s, "a");
if (fp == NULL) if (fp)
lua_pushnil();
else
{ {
if (out != stdout) fclose (out); if (out != stdout) fclose (out);
out = fp; out = fp;
@ -156,7 +150,7 @@ static char getformat (char *f, int *just, long *m, int *n)
break; break;
default: default:
t = 0; /* to avoid compiler warnings */ t = 0; /* to avoid compiler warnings */
lua_arg_error("read/write (format)"); lua_arg_check(0, "read/write (format)");
} }
*just = (*f == '<' || *f == '>' || *f == '|') ? *f++ : '>'; *just = (*f == '<' || *f == '>' || *f == '|') ? *f++ : '>';
if (isdigit(*f)) if (isdigit(*f))
@ -225,16 +219,11 @@ static void read_free (void)
while (isspace(c=fgetc(in))) while (isspace(c=fgetc(in)))
; ;
if (c == EOF) if (c == EOF)
{
lua_pushnil();
return; return;
}
if (c == '\"' || c == '\'') if (c == '\"' || c == '\'')
{ /* string */ { /* string */
c = read_until_char(c); c = read_until_char(c);
if (c == EOF) if (c != EOF)
lua_pushnil();
else
lua_pushstring(luaI_addchar(0)); lua_pushstring(luaI_addchar(0));
} }
else else
@ -274,8 +263,6 @@ static void io_read (void)
s = luaI_addchar(0); s = luaI_addchar(0);
if ((m >= 0 && strlen(s) == m) || (m < 0 && strlen(s) > 0)) if ((m >= 0 && strlen(s) == m) || (m < 0 && strlen(s) > 0))
lua_pushstring(s); lua_pushstring(s);
else
lua_pushnil();
break; break;
} }
@ -293,12 +280,10 @@ static void io_read (void)
} }
if (result == 1) if (result == 1)
lua_pushnumber(d); lua_pushnumber(d);
else
lua_pushnil();
break; break;
} }
default: default:
lua_arg_error("read (format)"); lua_arg_check(0, "read (format)");
} }
} }
} }
@ -452,8 +437,6 @@ static void io_write (void)
} }
if (status) if (status)
lua_pushnumber(status); lua_pushnumber(status);
else
lua_pushnil();
} }
/* /*