MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / g_read

Function g_read

lua/liolib.c:339–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337
338
339static int g_read (lua_State *L, FILE *f, int first) {
340 int nargs = lua_gettop(L) - 1;
341 int success;
342 int n;
343 clearerr(f);
344 if (nargs == 0) { /* no arguments? */
345 success = read_line(L, f);
346 n = first+1; /* to return 1 result */
347 }
348 else { /* ensure stack space for all results and for auxlib's buffer */
349 luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
350 success = 1;
351 for (n = first; nargs-- && success; n++) {
352 if (lua_type(L, n) == LUA_TNUMBER) {
353 size_t l = (size_t)lua_tointeger(L, n);
354 success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
355 }
356 else {
357 const char *p = lua_tostring(L, n);
358 luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
359 switch (p[1]) {
360 case 'n': /* number */
361 success = read_number(L, f);
362 break;
363 case 'l': /* line */
364 success = read_line(L, f);
365 break;
366 case 'a': /* file */
367 read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */
368 success = 1; /* always success */
369 break;
370 default:
371 return luaL_argerror(L, n, "invalid format");
372 }
373 }
374 }
375 }
376 if (ferror(f))
377 return pushresult(L, 0, NULL);
378 if (!success) {
379 lua_pop(L, 1); /* remove last result */
380 lua_pushnil(L); /* push nil instead */
381 }
382 return n - first;
383}
384
385
386static int io_read (lua_State *L) {

Callers 2

io_readFunction · 0.85
f_readFunction · 0.85

Calls 11

lua_gettopFunction · 0.85
luaL_checkstackFunction · 0.85
lua_typeFunction · 0.85
lua_tointegerFunction · 0.85
test_eofFunction · 0.85
read_charsFunction · 0.85
read_numberFunction · 0.85
luaL_argerrorFunction · 0.85
pushresultFunction · 0.85
lua_pushnilFunction · 0.85
read_lineFunction · 0.70

Tested by

no test coverage detected