From 2bae11a49a4b69b9f0b51dfd33c703f261b789cd Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sun, 20 Feb 2011 21:07:19 +0100 Subject: [PATCH] From Lua 5.2: fp:read("*L"). --- src/lib_io.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib_io.c b/src/lib_io.c index 66b174f8..d3dac7a0 100644 --- a/src/lib_io.c +++ b/src/lib_io.c @@ -3,7 +3,7 @@ ** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h ** ** Major portions taken verbatim or adapted from the Lua interpreter. -** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h +** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h */ #include @@ -153,7 +153,7 @@ static int io_file_testeof(lua_State *L, FILE *fp) return (c != EOF); } -static int io_file_readline(lua_State *L, FILE *fp) +static int io_file_readline(lua_State *L, FILE *fp, size_t chop) { luaL_Buffer b; luaL_buffinit(L, &b); @@ -168,7 +168,7 @@ static int io_file_readline(lua_State *L, FILE *fp) if (len == 0 || p[len-1] != '\n') { /* Partial line? */ luaL_addsize(&b, len); } else { - luaL_addsize(&b, len - 1); /* Don't include EOL. */ + luaL_addsize(&b, len - chop); /* Keep or remove EOL. */ luaL_pushresult(&b); return 1; /* Got at least an EOL. */ } @@ -198,7 +198,7 @@ static int io_file_read(lua_State *L, FILE *fp, int start) int ok, n, nargs = (int)(L->top - L->base) - start; clearerr(fp); if (nargs == 0) { - ok = io_file_readline(L, fp); + ok = io_file_readline(L, fp, 1); n = start+1; /* Return 1 result. */ } else { /* The results plus the buffers go on top of the args. */ @@ -211,8 +211,8 @@ static int io_file_read(lua_State *L, FILE *fp, int start) lj_err_arg(L, n+1, LJ_ERR_INVOPT); if (p[1] == 'n') ok = io_file_readnum(L, fp); - else if (p[1] == 'l') - ok = io_file_readline(L, fp); + else if ((p[1] & ~0x20) == 'L') + ok = io_file_readline(L, fp, (p[1] == 'l')); else if (p[1] == 'a') io_file_readchars(L, fp, ~((size_t)0)); else @@ -459,7 +459,7 @@ LJLIB_CF(io_output) LJLIB_NOREG LJLIB_CF(io_lines_iter) { IOFileUD *iof = io_tofile(L); - int ok = io_file_readline(L, iof->fp); + int ok = io_file_readline(L, iof->fp, 1); if (ferror(iof->fp)) lj_err_callermsg(L, strerror(errno)); if (!ok && (iof->type & IOFILE_FLAG_CLOSE)) -- 2.11.4.GIT