MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / g_read

Function g_read

lib/lua/src/liolib.c:569–617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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