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

Function g_read

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

Source from the content-addressed store, hash-verified

564
565
566static int g_read (lua_State *L, FILE *f, int first) {
567 int nargs = lua_gettop(L) - 1;
568 int n, success;
569 clearerr(f);
570 if (nargs == 0) { /* no arguments? */
571 success = read_line(L, f, 1);
572 n = first + 1; /* to return 1 result */
573 }
574 else {
575 /* ensure stack space for all results and for auxlib's buffer */
576 luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
577 success = 1;
578 for (n = first; nargs-- && success; n++) {
579 if (lua_type(L, n) == LUA_TNUMBER) {
580 size_t l = (size_t)luaL_checkinteger(L, n);
581 success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
582 }
583 else {
584 const char *p = luaL_checkstring(L, n);
585 if (*p == '*') p++; /* skip optional '*' (for compatibility) */
586 switch (*p) {
587 case 'n': /* number */
588 success = read_number(L, f);
589 break;
590 case 'l': /* line */
591 success = read_line(L, f, 1);
592 break;
593 case 'L': /* line with end-of-line */
594 success = read_line(L, f, 0);
595 break;
596 case 'a': /* file */
597 read_all(L, f); /* read entire file */
598 success = 1; /* always success */
599 break;
600 default:
601 return luaL_argerror(L, n, "invalid format");
602 }
603 }
604 }
605 }
606 if (ferror(f))
607 return luaL_fileresult(L, 0, NULL);
608 if (!success) {
609 lua_pop(L, 1); /* remove last result */
610 luaL_pushfail(L); /* push nil instead */
611 }
612 return n - first;
613}
614
615
616static int io_read (lua_State *L) {

Callers 3

io_readFunction · 0.85
f_readFunction · 0.85
io_readlineFunction · 0.85

Calls 11

lua_gettopFunction · 0.85
read_lineFunction · 0.85
luaL_checkstackFunction · 0.85
lua_typeFunction · 0.85
luaL_checkintegerFunction · 0.85
test_eofFunction · 0.85
read_charsFunction · 0.85
read_numberFunction · 0.85
read_allFunction · 0.85
luaL_argerrorFunction · 0.85
luaL_fileresultFunction · 0.85

Tested by

no test coverage detected