MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / read_line

Function read_line

3rd/lua-5.4.3/src/liolib.c:519–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517
518
519static int read_line (lua_State *L, FILE *f, int chop) {
520 luaL_Buffer b;
521 int c;
522 luaL_buffinit(L, &b);
523 do { /* may need to read several chunks to get whole line */
524 char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */
525 int i = 0;
526 l_lockfile(f); /* no memory errors can happen inside the lock */
527 while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
528 buff[i++] = c; /* read up to end of line or buffer limit */
529 l_unlockfile(f);
530 luaL_addsize(&b, i);
531 } while (c != EOF && c != '\n'); /* repeat until end of line */
532 if (!chop && c == '\n') /* want a newline and have one? */
533 luaL_addchar(&b, c); /* add ending newline to result */
534 luaL_pushresult(&b); /* close buffer */
535 /* return ok if read something (either a newline or something else) */
536 return (c == '\n' || lua_rawlen(L, -1) > 0);
537}
538
539
540static void read_all (lua_State *L, FILE *f) {

Callers 1

g_readFunction · 0.85

Calls 2

luaL_buffinitFunction · 0.85
luaL_pushresultFunction · 0.85

Tested by

no test coverage detected