diff options
-rw-r--r-- | liolib.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.111 2013/03/21 13:57:27 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.112 2013/04/11 18:34:06 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -347,6 +347,19 @@ static int io_lines (lua_State *L) { | |||
347 | */ | 347 | */ |
348 | 348 | ||
349 | 349 | ||
350 | static int read_integer (lua_State *L, FILE *f) { | ||
351 | lua_Integer d; | ||
352 | if (fscanf(f, LUA_INTEGER_SCAN, &d) == 1) { | ||
353 | lua_pushinteger(L, d); | ||
354 | return 1; | ||
355 | } | ||
356 | else { | ||
357 | lua_pushnil(L); /* "result" to be removed */ | ||
358 | return 0; /* read fails */ | ||
359 | } | ||
360 | } | ||
361 | |||
362 | |||
350 | static int read_number (lua_State *L, FILE *f) { | 363 | static int read_number (lua_State *L, FILE *f) { |
351 | lua_Number d; | 364 | lua_Number d; |
352 | if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { | 365 | if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { |
@@ -442,6 +455,9 @@ static int g_read (lua_State *L, FILE *f, int first) { | |||
442 | const char *p = lua_tostring(L, n); | 455 | const char *p = lua_tostring(L, n); |
443 | luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); | 456 | luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); |
444 | switch (p[1]) { | 457 | switch (p[1]) { |
458 | case 'i': /* integer */ | ||
459 | success = read_integer(L, f); | ||
460 | break; | ||
445 | case 'n': /* number */ | 461 | case 'n': /* number */ |
446 | success = read_number(L, f); | 462 | success = read_number(L, f); |
447 | break; | 463 | break; |