diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-17 14:02:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-17 14:02:29 -0300 |
commit | eea734aa881002e90bd9130171a2b94cd9dc3267 (patch) | |
tree | b2816a614fca723d8c0b06e96cd093438e6e098b /iolib.c | |
parent | b6d91e24e23edfe98ad732660fd456e91658edb9 (diff) | |
download | lua-eea734aa881002e90bd9130171a2b94cd9dc3267.tar.gz lua-eea734aa881002e90bd9130171a2b94cd9dc3267.tar.bz2 lua-eea734aa881002e90bd9130171a2b94cd9dc3267.zip |
new module 'auxlib' centralizes functions to get/check parameters.
Diffstat (limited to 'iolib.c')
-rw-r--r-- | iolib.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -58,7 +58,7 @@ static void io_readfrom (void) | |||
58 | else if (lua_isuserdata(f)) | 58 | else if (lua_isuserdata(f)) |
59 | lua_infile = lua_getuserdata(f); | 59 | lua_infile = lua_getuserdata(f); |
60 | else { | 60 | else { |
61 | char *s = lua_check_string(1, "readfrom"); | 61 | char *s = luaL_check_string(1, "readfrom"); |
62 | FILE *fp = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); | 62 | FILE *fp = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); |
63 | if (fp) | 63 | if (fp) |
64 | lua_infile = fp; | 64 | lua_infile = fp; |
@@ -79,7 +79,7 @@ static void io_writeto (void) | |||
79 | else if (lua_isuserdata(f)) | 79 | else if (lua_isuserdata(f)) |
80 | lua_outfile = lua_getuserdata(f); | 80 | lua_outfile = lua_getuserdata(f); |
81 | else { | 81 | else { |
82 | char *s = lua_check_string(1, "writeto"); | 82 | char *s = luaL_check_string(1, "writeto"); |
83 | FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); | 83 | FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); |
84 | if (fp) | 84 | if (fp) |
85 | lua_outfile = fp; | 85 | lua_outfile = fp; |
@@ -94,7 +94,7 @@ static void io_writeto (void) | |||
94 | 94 | ||
95 | static void io_appendto (void) | 95 | static void io_appendto (void) |
96 | { | 96 | { |
97 | char *s = lua_check_string(1, "appendto"); | 97 | char *s = luaL_check_string(1, "appendto"); |
98 | FILE *fp = fopen (s, "a"); | 98 | FILE *fp = fopen (s, "a"); |
99 | if (fp != NULL) { | 99 | if (fp != NULL) { |
100 | lua_outfile = fp; | 100 | lua_outfile = fp; |
@@ -110,7 +110,7 @@ static void io_appendto (void) | |||
110 | static void io_read (void) | 110 | static void io_read (void) |
111 | { | 111 | { |
112 | char *buff; | 112 | char *buff; |
113 | char *p = lua_opt_string(1, "[^\n]*{\n}", "read"); | 113 | char *p = luaL_opt_string(1, "[^\n]*{\n}", "read"); |
114 | int inskip = 0; /* to control {skips} */ | 114 | int inskip = 0; /* to control {skips} */ |
115 | int c = NEED_OTHER; | 115 | int c = NEED_OTHER; |
116 | luaI_addchar(0); | 116 | luaI_addchar(0); |
@@ -161,7 +161,7 @@ static void io_write (void) | |||
161 | int arg = 1; | 161 | int arg = 1; |
162 | int status = 1; | 162 | int status = 1; |
163 | char *s; | 163 | char *s; |
164 | while ((s = lua_opt_string(arg++, NULL, "write")) != NULL) | 164 | while ((s = luaL_opt_string(arg++, NULL, "write")) != NULL) |
165 | status = status && (fputs(s, lua_outfile) != EOF); | 165 | status = status && (fputs(s, lua_outfile) != EOF); |
166 | pushresult(status); | 166 | pushresult(status); |
167 | } | 167 | } |
@@ -169,20 +169,20 @@ static void io_write (void) | |||
169 | 169 | ||
170 | static void io_execute (void) | 170 | static void io_execute (void) |
171 | { | 171 | { |
172 | lua_pushnumber(system(lua_check_string(1, "execute"))); | 172 | lua_pushnumber(system(luaL_check_string(1, "execute"))); |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | static void io_remove (void) | 176 | static void io_remove (void) |
177 | { | 177 | { |
178 | pushresult(remove(lua_check_string(1, "remove")) == 0); | 178 | pushresult(remove(luaL_check_string(1, "remove")) == 0); |
179 | } | 179 | } |
180 | 180 | ||
181 | 181 | ||
182 | static void io_rename (void) | 182 | static void io_rename (void) |
183 | { | 183 | { |
184 | pushresult(rename(lua_check_string(1, "rename"), | 184 | pushresult(rename(luaL_check_string(1, "rename"), |
185 | lua_check_string(2, "rename")) == 0); | 185 | luaL_check_string(2, "rename")) == 0); |
186 | } | 186 | } |
187 | 187 | ||
188 | 188 | ||
@@ -195,7 +195,7 @@ static void io_tmpname (void) | |||
195 | 195 | ||
196 | static void io_getenv (void) | 196 | static void io_getenv (void) |
197 | { | 197 | { |
198 | lua_pushstring(getenv(lua_check_string(1, "getenv"))); /* if NULL push nil */ | 198 | lua_pushstring(getenv(luaL_check_string(1, "getenv"))); /* if NULL push nil */ |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
@@ -203,7 +203,7 @@ static void io_date (void) | |||
203 | { | 203 | { |
204 | time_t t; | 204 | time_t t; |
205 | struct tm *tm; | 205 | struct tm *tm; |
206 | char *s = lua_opt_string(1, "%c", "date"); | 206 | char *s = luaL_opt_string(1, "%c", "date"); |
207 | char b[BUFSIZ]; | 207 | char b[BUFSIZ]; |
208 | time(&t); tm = localtime(&t); | 208 | time(&t); tm = localtime(&t); |
209 | if (strftime(b,sizeof(b),s,tm)) | 209 | if (strftime(b,sizeof(b),s,tm)) |
@@ -269,7 +269,7 @@ static void lua_printstack (FILE *f) | |||
269 | 269 | ||
270 | static void errorfb (void) | 270 | static void errorfb (void) |
271 | { | 271 | { |
272 | char *s = lua_opt_string(1, "(no messsage)", NULL); | 272 | char *s = luaL_opt_string(1, "(no messsage)", NULL); |
273 | fprintf(stderr, "lua: %s\n", s); | 273 | fprintf(stderr, "lua: %s\n", s); |
274 | lua_printstack(stderr); | 274 | lua_printstack(stderr); |
275 | } | 275 | } |