diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-28 15:46:49 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-05-28 15:46:49 -0300 |
commit | b293ae0577bebaca7169cb4f041b800641d5e2c4 (patch) | |
tree | bda609d72277433bda3537ac50ed8fecf9a73898 /liolib.c | |
parent | d9f40e3f6fb61650240c47d548bee69b24b07859 (diff) | |
download | lua-b293ae0577bebaca7169cb4f041b800641d5e2c4.tar.gz lua-b293ae0577bebaca7169cb4f041b800641d5e2c4.tar.bz2 lua-b293ae0577bebaca7169cb4f041b800641d5e2c4.zip |
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'
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -504,17 +504,17 @@ static int test_eof (lua_State *L, FILE *f) { | |||
504 | 504 | ||
505 | static int read_line (lua_State *L, FILE *f, int chop) { | 505 | static int read_line (lua_State *L, FILE *f, int chop) { |
506 | luaL_Buffer b; | 506 | luaL_Buffer b; |
507 | int c = '\0'; | 507 | int c; |
508 | luaL_buffinit(L, &b); | 508 | luaL_buffinit(L, &b); |
509 | while (c != EOF && c != '\n') { /* repeat until end of line */ | 509 | do { /* may need to read several chunks to get whole line */ |
510 | char *buff = luaL_prepbuffer(&b); /* preallocate buffer */ | 510 | char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */ |
511 | int i = 0; | 511 | int i = 0; |
512 | l_lockfile(f); /* no memory errors can happen inside the lock */ | 512 | l_lockfile(f); /* no memory errors can happen inside the lock */ |
513 | while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') | 513 | while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') |
514 | buff[i++] = c; | 514 | buff[i++] = c; /* read up to end of line or buffer limit */ |
515 | l_unlockfile(f); | 515 | l_unlockfile(f); |
516 | luaL_addsize(&b, i); | 516 | luaL_addsize(&b, i); |
517 | } | 517 | } while (c != EOF && c != '\n'); /* repeat until end of line */ |
518 | if (!chop && c == '\n') /* want a newline and have one? */ | 518 | if (!chop && c == '\n') /* want a newline and have one? */ |
519 | luaL_addchar(&b, c); /* add ending newline to result */ | 519 | luaL_addchar(&b, c); /* add ending newline to result */ |
520 | luaL_pushresult(&b); /* close buffer */ | 520 | luaL_pushresult(&b); /* close buffer */ |