diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-06 11:08:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-06 11:08:08 -0300 |
commit | 3a9516ffc8de0d33051f83dc786dba615d6bac49 (patch) | |
tree | 9608796ca5abb4a724d70d99cb34dd818eb95662 /iolib.c | |
parent | 42fa305649199712aad1c96beadb944b01277e3f (diff) | |
download | lua-3a9516ffc8de0d33051f83dc786dba615d6bac49.tar.gz lua-3a9516ffc8de0d33051f83dc786dba615d6bac49.tar.bz2 lua-3a9516ffc8de0d33051f83dc786dba615d6bac49.zip |
luaL check functions do not need the function name (it can be
accessed via luadebug interface).
Diffstat (limited to 'iolib.c')
-rw-r--r-- | iolib.c | 33 |
1 files changed, 16 insertions, 17 deletions
@@ -61,7 +61,7 @@ static void io_readfrom (void) | |||
61 | else if (lua_tag(f) == lua_tagio) | 61 | else if (lua_tag(f) == lua_tagio) |
62 | lua_infile = lua_getuserdata(f); | 62 | lua_infile = lua_getuserdata(f); |
63 | else { | 63 | else { |
64 | char *s = luaL_check_string(1, "readfrom"); | 64 | char *s = luaL_check_string(1); |
65 | FILE *fp = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); | 65 | FILE *fp = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); |
66 | if (fp) | 66 | if (fp) |
67 | lua_infile = fp; | 67 | lua_infile = fp; |
@@ -82,7 +82,7 @@ static void io_writeto (void) | |||
82 | else if (lua_tag(f) == lua_tagio) | 82 | else if (lua_tag(f) == lua_tagio) |
83 | lua_outfile = lua_getuserdata(f); | 83 | lua_outfile = lua_getuserdata(f); |
84 | else { | 84 | else { |
85 | char *s = luaL_check_string(1, "writeto"); | 85 | char *s = luaL_check_string(1); |
86 | FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); | 86 | FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); |
87 | if (fp) | 87 | if (fp) |
88 | lua_outfile = fp; | 88 | lua_outfile = fp; |
@@ -97,7 +97,7 @@ static void io_writeto (void) | |||
97 | 97 | ||
98 | static void io_appendto (void) | 98 | static void io_appendto (void) |
99 | { | 99 | { |
100 | char *s = luaL_check_string(1, "appendto"); | 100 | char *s = luaL_check_string(1); |
101 | FILE *fp = fopen (s, "a"); | 101 | FILE *fp = fopen (s, "a"); |
102 | if (fp != NULL) { | 102 | if (fp != NULL) { |
103 | lua_outfile = fp; | 103 | lua_outfile = fp; |
@@ -113,7 +113,7 @@ static void io_appendto (void) | |||
113 | static void io_read (void) | 113 | static void io_read (void) |
114 | { | 114 | { |
115 | char *buff; | 115 | char *buff; |
116 | char *p = luaL_opt_string(1, "[^\n]*{\n}", "read"); | 116 | char *p = luaL_opt_string(1, "[^\n]*{\n}"); |
117 | int inskip = 0; /* to control {skips} */ | 117 | int inskip = 0; /* to control {skips} */ |
118 | int c = NEED_OTHER; | 118 | int c = NEED_OTHER; |
119 | luaI_emptybuff(); | 119 | luaI_emptybuff(); |
@@ -164,7 +164,7 @@ static void io_write (void) | |||
164 | int arg = 1; | 164 | int arg = 1; |
165 | int status = 1; | 165 | int status = 1; |
166 | char *s; | 166 | char *s; |
167 | while ((s = luaL_opt_string(arg++, NULL, "write")) != NULL) | 167 | while ((s = luaL_opt_string(arg++, NULL)) != NULL) |
168 | status = status && (fputs(s, lua_outfile) != EOF); | 168 | status = status && (fputs(s, lua_outfile) != EOF); |
169 | pushresult(status); | 169 | pushresult(status); |
170 | } | 170 | } |
@@ -172,20 +172,20 @@ static void io_write (void) | |||
172 | 172 | ||
173 | static void io_execute (void) | 173 | static void io_execute (void) |
174 | { | 174 | { |
175 | lua_pushnumber(system(luaL_check_string(1, "execute"))); | 175 | lua_pushnumber(system(luaL_check_string(1))); |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
179 | static void io_remove (void) | 179 | static void io_remove (void) |
180 | { | 180 | { |
181 | pushresult(remove(luaL_check_string(1, "remove")) == 0); | 181 | pushresult(remove(luaL_check_string(1)) == 0); |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | static void io_rename (void) | 185 | static void io_rename (void) |
186 | { | 186 | { |
187 | pushresult(rename(luaL_check_string(1, "rename"), | 187 | pushresult(rename(luaL_check_string(1), |
188 | luaL_check_string(2, "rename")) == 0); | 188 | luaL_check_string(2)) == 0); |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
@@ -198,7 +198,7 @@ static void io_tmpname (void) | |||
198 | 198 | ||
199 | static void io_getenv (void) | 199 | static void io_getenv (void) |
200 | { | 200 | { |
201 | lua_pushstring(getenv(luaL_check_string(1, "getenv"))); /* if NULL push nil */ | 201 | lua_pushstring(getenv(luaL_check_string(1))); /* if NULL push nil */ |
202 | } | 202 | } |
203 | 203 | ||
204 | 204 | ||
@@ -206,7 +206,7 @@ static void io_date (void) | |||
206 | { | 206 | { |
207 | time_t t; | 207 | time_t t; |
208 | struct tm *tm; | 208 | struct tm *tm; |
209 | char *s = luaL_opt_string(1, "%c", "date"); | 209 | char *s = luaL_opt_string(1, "%c"); |
210 | char b[BUFSIZ]; | 210 | char b[BUFSIZ]; |
211 | time(&t); tm = localtime(&t); | 211 | time(&t); tm = localtime(&t); |
212 | if (strftime(b,sizeof(b),s,tm)) | 212 | if (strftime(b,sizeof(b),s,tm)) |
@@ -282,8 +282,8 @@ static void errorfb (void) | |||
282 | static void getbyte (void) | 282 | static void getbyte (void) |
283 | { | 283 | { |
284 | lua_Object ud = lua_getparam(1); | 284 | lua_Object ud = lua_getparam(1); |
285 | int i = luaL_opt_number(2, -1, "getbyte"); | 285 | int i = luaL_opt_number(2, -1); |
286 | luaL_arg_check(lua_isuserdata(ud), "getbyte", 1, "userdata expected"); | 286 | luaL_arg_check(lua_isuserdata(ud), 1, "userdata expected"); |
287 | if (i == -1) | 287 | if (i == -1) |
288 | lua_pushnumber(lua_getbindatasize(ud)); | 288 | lua_pushnumber(lua_getbindatasize(ud)); |
289 | else { | 289 | else { |
@@ -298,10 +298,10 @@ static void getbyte (void) | |||
298 | static void createuserdata (void) | 298 | static void createuserdata (void) |
299 | { | 299 | { |
300 | lua_Object t = lua_getparam(1); | 300 | lua_Object t = lua_getparam(1); |
301 | int tag = luaL_opt_number(2, 0, "createud"); | 301 | int tag = luaL_opt_number(2, 0); |
302 | int i; | 302 | int i; |
303 | luaI_emptybuff(); | 303 | luaI_emptybuff(); |
304 | luaL_arg_check(lua_istable(t), "createud", 1, "table expected"); | 304 | luaL_arg_check(lua_istable(t), 1, "table expected"); |
305 | for (i=0; ; i++) { | 305 | for (i=0; ; i++) { |
306 | lua_Object o; | 306 | lua_Object o; |
307 | lua_beginblock(); | 307 | lua_beginblock(); |
@@ -312,8 +312,7 @@ static void createuserdata (void) | |||
312 | lua_endblock(); | 312 | lua_endblock(); |
313 | break; | 313 | break; |
314 | } | 314 | } |
315 | luaL_arg_check(lua_isnumber(o), "createud", 1, | 315 | luaL_arg_check(lua_isnumber(o), 1, "table values must be numbers"); |
316 | "table values must be numbers"); | ||
317 | luaI_addchar(lua_getnumber(o)); | 316 | luaI_addchar(lua_getnumber(o)); |
318 | lua_endblock(); | 317 | lua_endblock(); |
319 | } | 318 | } |