diff options
Diffstat (limited to 'iolib.c')
-rw-r--r-- | iolib.c | 22 |
1 files changed, 17 insertions, 5 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.28 1995/11/10 17:55:48 roberto Exp roberto $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.29 1995/11/10 18:32:59 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <ctype.h> | 9 | #include <ctype.h> |
@@ -289,12 +289,19 @@ static void io_read (void) | |||
289 | switch (getformat(lua_check_string(1, "read"), &dummy1, &m, &dummy2)) | 289 | switch (getformat(lua_check_string(1, "read"), &dummy1, &m, &dummy2)) |
290 | { | 290 | { |
291 | case 's': | 291 | case 's': |
292 | { | ||
293 | char *s; | ||
292 | if (m < 0) | 294 | if (m < 0) |
293 | read_until_blank(); | 295 | read_until_blank(); |
294 | else | 296 | else |
295 | read_m(m); | 297 | read_m(m); |
296 | lua_pushstring(add_char(0)); | 298 | s = add_char(0); |
299 | if ((m >= 0 && strlen(s) == m) || (m < 0 && strlen(s) > 0)) | ||
300 | lua_pushstring(s); | ||
301 | else | ||
302 | lua_pushnil(); | ||
297 | break; | 303 | break; |
304 | } | ||
298 | 305 | ||
299 | case 'i': /* can read as float, since it makes no difference to Lua */ | 306 | case 'i': /* can read as float, since it makes no difference to Lua */ |
300 | case 'f': | 307 | case 'f': |
@@ -324,8 +331,13 @@ static void io_read (void) | |||
324 | */ | 331 | */ |
325 | static void io_readuntil (void) | 332 | static void io_readuntil (void) |
326 | { | 333 | { |
327 | int del = *lua_check_string(1, "readuntil"); | 334 | int del, c; |
328 | int c = read_until_char(del); | 335 | lua_Object p = lua_getparam(1); |
336 | if (p == LUA_NOOBJECT || lua_isnil(p)) | ||
337 | del = EOF; | ||
338 | else | ||
339 | del = *lua_check_string(1, "readuntil"); | ||
340 | c = read_until_char(del); | ||
329 | if (c != EOF) ungetc(c,in); | 341 | if (c != EOF) ungetc(c,in); |
330 | lua_pushstring(add_char(0)); | 342 | lua_pushstring(add_char(0)); |
331 | } | 343 | } |
@@ -560,7 +572,7 @@ void lua_printstack (FILE *f) | |||
560 | char *name; | 572 | char *name; |
561 | int currentline; | 573 | int currentline; |
562 | fprintf(f, "\t"); | 574 | fprintf(f, "\t"); |
563 | switch (*getobjname(func, &name)) | 575 | switch (*lua_getobjname(func, &name)) |
564 | { | 576 | { |
565 | case 'g': | 577 | case 'g': |
566 | fprintf(f, "function %s", name); | 578 | fprintf(f, "function %s", name); |