MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / g_read

Function g_read

Source/Misc/lua/src/lua.c:12245–12289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12243
12244
12245static int g_read (lua_State *L, FILE *f, int first) {
12246int nargs = lua_gettop(L) - 1;
12247int success;
12248int n;
12249clearerr(f);
12250if (nargs == 0) { /* no arguments? */
12251success = read_line(L, f);
12252n = first+1; /* to return 1 result */
12253}
12254else { /* ensure stack space for all results and for auxlib's buffer */
12255luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
12256success = 1;
12257for (n = first; nargs-- && success; n++) {
12258if (lua_type(L, n) == LUA_TNUMBER) {
12259size_t l = (size_t)lua_tointeger(L, n);
12260success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
12261}
12262else {
12263const char *p = lua_tostring(L, n);
12264luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
12265switch (p[1]) {
12266case 'n': /* number */
12267success = read_number(L, f);
12268break;
12269case 'l': /* line */
12270success = read_line(L, f);
12271break;
12272case 'a': /* file */
12273read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */
12274success = 1; /* always success */
12275break;
12276default:
12277return luaL_argerror(L, n, "invalid format");
12278}
12279}
12280}
12281}
12282if (ferror(f))
12283return pushresult(L, 0, NULL);
12284if (!success) {
12285lua_pop(L, 1); /* remove last result */
12286lua_pushnil(L); /* push nil instead */
12287}
12288return n - first;
12289}
12290
12291
12292static int io_read (lua_State *L) {

Callers 2

io_readFunction · 0.85
f_readFunction · 0.85

Calls 11

lua_gettopFunction · 0.85
read_lineFunction · 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

Tested by

no test coverage detected