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

Function g_read

engine/lua/src/lua/liolib.c:335–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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