MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / read_line

Function read_line

third-party/lua-5.3.5/src/liolib.c:482–500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

480
481
482static int read_line (lua_State *L, FILE *f, int chop) {
483 luaL_Buffer b;
484 int c = '\0';
485 luaL_buffinit(L, &b);
486 while (c != EOF && c != '\n') { /* repeat until end of line */
487 char *buff = luaL_prepbuffer(&b); /* preallocate buffer */
488 int i = 0;
489 l_lockfile(f); /* no memory errors can happen inside the lock */
490 while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
491 buff[i++] = c;
492 l_unlockfile(f);
493 luaL_addsize(&b, i);
494 }
495 if (!chop && c == '\n') /* want a newline and have one? */
496 luaL_addchar(&b, c); /* add ending newline to result */
497 luaL_pushresult(&b); /* close buffer */
498 /* return ok if read something (either a newline or something else) */
499 return (c == '\n' || lua_rawlen(L, -1) > 0);
500}
501
502
503static void read_all (lua_State *L, FILE *f) {

Callers 1

g_readFunction · 0.70

Calls 4

luaL_prepbufferFunction · 0.85
luaL_buffinitFunction · 0.70
luaL_pushresultFunction · 0.70
lua_rawlenFunction · 0.70

Tested by

no test coverage detected