MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / read_line

Function read_line

Source/Misc/lua/src/lua.c:12205–12224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12203
12204
12205static int read_line (lua_State *L, FILE *f) {
12206luaL_Buffer b;
12207luaL_buffinit(L, &b);
12208for (;;) {
12209size_t l;
12210char *p = luaL_prepbuffer(&b);
12211if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
12212luaL_pushresult(&b); /* close buffer */
12213return (lua_objlen(L, -1) > 0); /* check whether read something */
12214}
12215l = strlen(p);
12216if (l == 0 || p[l-1] != '\n')
12217luaL_addsize(&b, l);
12218else {
12219luaL_addsize(&b, l - 1); /* do not include `eol' */
12220luaL_pushresult(&b); /* close buffer */
12221return 1; /* read at least an `eol' */
12222}
12223}
12224}
12225
12226
12227static int read_chars (lua_State *L, FILE *f, size_t n) {

Callers 2

g_readFunction · 0.85
io_readlineFunction · 0.85

Calls 4

luaL_buffinitFunction · 0.85
luaL_prepbufferFunction · 0.85
luaL_pushresultFunction · 0.85
lua_objlenFunction · 0.85

Tested by

no test coverage detected