diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-23 11:54:11 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-23 11:54:11 -0200 |
commit | fa71304e54f304ceceddef3a4b97b38228822e94 (patch) | |
tree | 52af1aed04b7ff339ecc104af877fdc3bb12c0ed | |
parent | b5745d11cdd93c819f8e881504eb534c7e13badd (diff) | |
download | lua-fa71304e54f304ceceddef3a4b97b38228822e94.tar.gz lua-fa71304e54f304ceceddef3a4b97b38228822e94.tar.bz2 lua-fa71304e54f304ceceddef3a4b97b38228822e94.zip |
"dofile" now accepts NULL as parameter, to run stdin.
-rw-r--r-- | inout.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -5,7 +5,7 @@ | |||
5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | char *rcs_inout="$Id: inout.c,v 2.22 1995/10/09 13:06:20 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.23 1995/10/17 11:58:41 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
@@ -60,7 +60,13 @@ static int stringinput (void) | |||
60 | char *lua_openfile (char *fn) | 60 | char *lua_openfile (char *fn) |
61 | { | 61 | { |
62 | lua_setinput (fileinput); | 62 | lua_setinput (fileinput); |
63 | fp = fopen (fn, "r"); | 63 | if (fn == NULL) |
64 | { | ||
65 | fp = stdin; | ||
66 | fn = "(stdin)"; | ||
67 | } | ||
68 | else | ||
69 | fp = fopen (fn, "r"); | ||
64 | if (fp == NULL) | 70 | if (fp == NULL) |
65 | { | 71 | { |
66 | static char buff[255]; | 72 | static char buff[255]; |
@@ -77,7 +83,7 @@ char *lua_openfile (char *fn) | |||
77 | */ | 83 | */ |
78 | void lua_closefile (void) | 84 | void lua_closefile (void) |
79 | { | 85 | { |
80 | if (fp != NULL) | 86 | if (fp != NULL && fp != stdin) |
81 | { | 87 | { |
82 | fclose (fp); | 88 | fclose (fp); |
83 | fp = NULL; | 89 | fp = NULL; |