MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / g_read

Function g_read

extlibs/lua/src/liolib.c:552–599  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550
551
552static int g_read (lua_State *L, FILE *f, int first) {
553 int nargs = lua_gettop(L) - 1;
554 int n, success;
555 clearerr(f);
556 if (nargs == 0) { /* no arguments? */
557 success = read_line(L, f, 1);
558 n = first + 1; /* to return 1 result */
559 }
560 else {
561 /* ensure stack space for all results and for auxlib's buffer */
562 luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
563 success = 1;
564 for (n = first; nargs-- && success; n++) {
565 if (lua_type(L, n) == LUA_TNUMBER) {
566 size_t l = (size_t)luaL_checkinteger(L, n);
567 success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
568 }
569 else {
570 const char *p = luaL_checkstring(L, n);
571 if (*p == '*') p++; /* skip optional '*' (for compatibility) */
572 switch (*p) {
573 case 'n': /* number */
574 success = read_number(L, f);
575 break;
576 case 'l': /* line */
577 success = read_line(L, f, 1);
578 break;
579 case 'L': /* line with end-of-line */
580 success = read_line(L, f, 0);
581 break;
582 case 'a': /* file */
583 read_all(L, f); /* read entire file */
584 success = 1; /* always success */
585 break;
586 default:
587 return luaL_argerror(L, n, "invalid format");
588 }
589 }
590 }
591 }
592 if (ferror(f))
593 return luaL_fileresult(L, 0, NULL);
594 if (!success) {
595 lua_pop(L, 1); /* remove last result */
596 luaL_pushfail(L); /* push nil instead */
597 }
598 return n - first;
599}
600
601
602static 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
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_checkstackFunction · 0.70
luaL_fileresultFunction · 0.70

Tested by

no test coverage detected