MCPcopy Create free account
hub / github.com/TASEmulators/fceux / g_read

Function g_read

src/lua/src/liolib.c:331–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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