From b293ae0577bebaca7169cb4f041b800641d5e2c4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 28 May 2019 15:46:49 -0300 Subject: Details - new error message for "attempt to assign to const variable" - note in the manual about compatibility options - comments - small changes in 'read_line' and 'pushstr' --- liolib.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'liolib.c') diff --git a/liolib.c b/liolib.c index fa6a0939..1484676d 100644 --- a/liolib.c +++ b/liolib.c @@ -504,17 +504,17 @@ static int test_eof (lua_State *L, FILE *f) { static int read_line (lua_State *L, FILE *f, int chop) { luaL_Buffer b; - int c = '\0'; + int c; luaL_buffinit(L, &b); - while (c != EOF && c != '\n') { /* repeat until end of line */ - char *buff = luaL_prepbuffer(&b); /* preallocate buffer */ + do { /* may need to read several chunks to get whole line */ + char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */ int i = 0; l_lockfile(f); /* no memory errors can happen inside the lock */ while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') - buff[i++] = c; + buff[i++] = c; /* read up to end of line or buffer limit */ l_unlockfile(f); luaL_addsize(&b, i); - } + } while (c != EOF && c != '\n'); /* repeat until end of line */ if (!chop && c == '\n') /* want a newline and have one? */ luaL_addchar(&b, c); /* add ending newline to result */ luaL_pushresult(&b); /* close buffer */ -- cgit v1.2.3-55-g6feb