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

Function g_read

third-party/lua-5.1.5/src/liolib.c:334–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332
333
334static int g_read (lua_State *L, FILE *f, int first) {
335 int nargs = lua_gettop(L) - 1;
336 int success;
337 int n;
338 clearerr(f);
339 if (nargs == 0) { /* no arguments? */
340 success = read_line(L, f);
341 n = first+1; /* to return 1 result */
342 }
343 else { /* ensure stack space for all results and for auxlib's buffer */
344 luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
345 success = 1;
346 for (n = first; nargs-- && success; n++) {
347 if (lua_type(L, n) == LUA_TNUMBER) {
348 size_t l = (size_t)lua_tointeger(L, n);
349 success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
350 }
351 else {
352 const char *p = lua_tostring(L, n);
353 luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
354 switch (p[1]) {
355 case 'n': /* number */
356 success = read_number(L, f);
357 break;
358 case 'l': /* line */
359 success = read_line(L, f);
360 break;
361 case 'a': /* file */
362 read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */
363 success = 1; /* always success */
364 break;
365 default:
366 return luaL_argerror(L, n, "invalid format");
367 }
368 }
369 }
370 }
371 if (ferror(f))
372 return pushresult(L, 0, NULL);
373 if (!success) {
374 lua_pop(L, 1); /* remove last result */
375 lua_pushnil(L); /* push nil instead */
376 }
377 return n - first;
378}
379
380
381static int io_read (lua_State *L) {

Callers 2

io_readFunction · 0.70
f_readFunction · 0.70

Calls 11

pushresultFunction · 0.85
lua_gettopFunction · 0.70
read_lineFunction · 0.70
luaL_checkstackFunction · 0.70
lua_typeFunction · 0.70
lua_tointegerFunction · 0.70
test_eofFunction · 0.70
read_charsFunction · 0.70
read_numberFunction · 0.70
luaL_argerrorFunction · 0.70
lua_pushnilFunction · 0.70

Tested by

no test coverage detected