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

Function g_read

third-party/lua-5.2.4/src/liolib.c:424–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

422
423
424static int g_read (lua_State *L, FILE *f, int first) {
425 int nargs = lua_gettop(L) - 1;
426 int success;
427 int n;
428 clearerr(f);
429 if (nargs == 0) { /* no arguments? */
430 success = read_line(L, f, 1);
431 n = first+1; /* to return 1 result */
432 }
433 else { /* ensure stack space for all results and for auxlib's buffer */
434 luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
435 success = 1;
436 for (n = first; nargs-- && success; n++) {
437 if (lua_type(L, n) == LUA_TNUMBER) {
438 size_t l = (size_t)lua_tointeger(L, n);
439 success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
440 }
441 else {
442 const char *p = lua_tostring(L, n);
443 luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
444 switch (p[1]) {
445 case 'n': /* number */
446 success = read_number(L, f);
447 break;
448 case 'l': /* line */
449 success = read_line(L, f, 1);
450 break;
451 case 'L': /* line with end-of-line */
452 success = read_line(L, f, 0);
453 break;
454 case 'a': /* file */
455 read_all(L, f); /* read entire file */
456 success = 1; /* always success */
457 break;
458 default:
459 return luaL_argerror(L, n, "invalid format");
460 }
461 }
462 }
463 }
464 if (ferror(f))
465 return luaL_fileresult(L, 0, NULL);
466 if (!success) {
467 lua_pop(L, 1); /* remove last result */
468 lua_pushnil(L); /* push nil instead */
469 }
470 return n - first;
471}
472
473
474static int io_read (lua_State *L) {

Callers 3

io_readFunction · 0.70
f_readFunction · 0.70
io_readlineFunction · 0.70

Calls 12

lua_gettopFunction · 0.70
read_lineFunction · 0.70
luaL_checkstackFunction · 0.70
lua_typeFunction · 0.70
test_eofFunction · 0.70
read_charsFunction · 0.70
read_numberFunction · 0.70
read_allFunction · 0.70
luaL_argerrorFunction · 0.70
luaL_fileresultFunction · 0.70
lua_pushnilFunction · 0.70
lua_tointegerFunction · 0.50

Tested by

no test coverage detected