diff options
| -rw-r--r-- | iolib.c | 29 |
1 files changed, 6 insertions, 23 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Input/output library to LUA | 3 | ** Input/output library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_iolib="$Id: iolib.c,v 1.45 1996/05/22 21:59:07 roberto Exp roberto $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.46 1996/05/27 14:06:58 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <ctype.h> | 9 | #include <ctype.h> |
| @@ -32,8 +32,6 @@ static void pushresult (int i) | |||
| 32 | { | 32 | { |
| 33 | if (i) | 33 | if (i) |
| 34 | lua_pushnumber (1); | 34 | lua_pushnumber (1); |
| 35 | else | ||
| 36 | lua_pushnil(); | ||
| 37 | } | 35 | } |
| 38 | 36 | ||
| 39 | static void closeread (void) | 37 | static void closeread (void) |
| @@ -106,9 +104,7 @@ static void io_writeto (void) | |||
| 106 | { | 104 | { |
| 107 | char *s = lua_check_string(1, "writeto"); | 105 | char *s = lua_check_string(1, "writeto"); |
| 108 | FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); | 106 | FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); |
| 109 | if (fp == NULL) | 107 | if (fp) |
| 110 | lua_pushnil(); | ||
| 111 | else | ||
| 112 | { | 108 | { |
| 113 | closewrite(); | 109 | closewrite(); |
| 114 | out = fp; | 110 | out = fp; |
| @@ -130,9 +126,7 @@ static void io_appendto (void) | |||
| 130 | { | 126 | { |
| 131 | char *s = lua_check_string(1, "appendto"); | 127 | char *s = lua_check_string(1, "appendto"); |
| 132 | FILE *fp = fopen (s, "a"); | 128 | FILE *fp = fopen (s, "a"); |
| 133 | if (fp == NULL) | 129 | if (fp) |
| 134 | lua_pushnil(); | ||
| 135 | else | ||
| 136 | { | 130 | { |
| 137 | if (out != stdout) fclose (out); | 131 | if (out != stdout) fclose (out); |
| 138 | out = fp; | 132 | out = fp; |
| @@ -156,7 +150,7 @@ static char getformat (char *f, int *just, long *m, int *n) | |||
| 156 | break; | 150 | break; |
| 157 | default: | 151 | default: |
| 158 | t = 0; /* to avoid compiler warnings */ | 152 | t = 0; /* to avoid compiler warnings */ |
| 159 | lua_arg_error("read/write (format)"); | 153 | lua_arg_check(0, "read/write (format)"); |
| 160 | } | 154 | } |
| 161 | *just = (*f == '<' || *f == '>' || *f == '|') ? *f++ : '>'; | 155 | *just = (*f == '<' || *f == '>' || *f == '|') ? *f++ : '>'; |
| 162 | if (isdigit(*f)) | 156 | if (isdigit(*f)) |
| @@ -225,16 +219,11 @@ static void read_free (void) | |||
| 225 | while (isspace(c=fgetc(in))) | 219 | while (isspace(c=fgetc(in))) |
| 226 | ; | 220 | ; |
| 227 | if (c == EOF) | 221 | if (c == EOF) |
| 228 | { | ||
| 229 | lua_pushnil(); | ||
| 230 | return; | 222 | return; |
| 231 | } | ||
| 232 | if (c == '\"' || c == '\'') | 223 | if (c == '\"' || c == '\'') |
| 233 | { /* string */ | 224 | { /* string */ |
| 234 | c = read_until_char(c); | 225 | c = read_until_char(c); |
| 235 | if (c == EOF) | 226 | if (c != EOF) |
| 236 | lua_pushnil(); | ||
| 237 | else | ||
| 238 | lua_pushstring(luaI_addchar(0)); | 227 | lua_pushstring(luaI_addchar(0)); |
| 239 | } | 228 | } |
| 240 | else | 229 | else |
| @@ -274,8 +263,6 @@ static void io_read (void) | |||
| 274 | s = luaI_addchar(0); | 263 | s = luaI_addchar(0); |
| 275 | if ((m >= 0 && strlen(s) == m) || (m < 0 && strlen(s) > 0)) | 264 | if ((m >= 0 && strlen(s) == m) || (m < 0 && strlen(s) > 0)) |
| 276 | lua_pushstring(s); | 265 | lua_pushstring(s); |
| 277 | else | ||
| 278 | lua_pushnil(); | ||
| 279 | break; | 266 | break; |
| 280 | } | 267 | } |
| 281 | 268 | ||
| @@ -293,12 +280,10 @@ static void io_read (void) | |||
| 293 | } | 280 | } |
| 294 | if (result == 1) | 281 | if (result == 1) |
| 295 | lua_pushnumber(d); | 282 | lua_pushnumber(d); |
| 296 | else | ||
| 297 | lua_pushnil(); | ||
| 298 | break; | 283 | break; |
| 299 | } | 284 | } |
| 300 | default: | 285 | default: |
| 301 | lua_arg_error("read (format)"); | 286 | lua_arg_check(0, "read (format)"); |
| 302 | } | 287 | } |
| 303 | } | 288 | } |
| 304 | } | 289 | } |
| @@ -452,8 +437,6 @@ static void io_write (void) | |||
| 452 | } | 437 | } |
| 453 | if (status) | 438 | if (status) |
| 454 | lua_pushnumber(status); | 439 | lua_pushnumber(status); |
| 455 | else | ||
| 456 | lua_pushnil(); | ||
| 457 | } | 440 | } |
| 458 | 441 | ||
| 459 | /* | 442 | /* |
