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

Function read_number

third-party/lua-5.5.0/src/liolib.c:479–510  ·  view source on GitHub ↗

** Read a number: first reads a valid prefix of a numeral into a buffer. ** Then it calls 'lua_stringtonumber' to check whether the format is ** correct and to convert it to a Lua number. */

Source from the content-addressed store, hash-verified

477** correct and to convert it to a Lua number.
478*/
479static int read_number (lua_State *L, FILE *f) {
480 RN rn;
481 int count = 0;
482 int hex = 0;
483 char decp[2];
484 rn.f = f; rn.n = 0;
485 decp[0] = lua_getlocaledecpoint(); /* get decimal point from locale */
486 decp[1] = '.'; /* always accept a dot */
487 l_lockfile(rn.f);
488 do { rn.c = l_getc(rn.f); } while (isspace(rn.c)); /* skip spaces */
489 test2(&rn, "-+"); /* optional sign */
490 if (test2(&rn, "00")) {
491 if (test2(&rn, "xX")) hex = 1; /* numeral is hexadecimal */
492 else count = 1; /* count initial '0' as a valid digit */
493 }
494 count += readdigits(&rn, hex); /* integral part */
495 if (test2(&rn, decp)) /* decimal point? */
496 count += readdigits(&rn, hex); /* fractional part */
497 if (count > 0 && test2(&rn, (hex ? "pP" : "eE"))) { /* exponent mark? */
498 test2(&rn, "-+"); /* exponent sign */
499 readdigits(&rn, 0); /* exponent digits */
500 }
501 ungetc(rn.c, rn.f); /* unread look-ahead char */
502 l_unlockfile(rn.f);
503 rn.buff[rn.n] = '\0'; /* finish string */
504 if (l_likely(lua_stringtonumber(L, rn.buff)))
505 return 1; /* ok, it is a valid number */
506 else { /* invalid format */
507 lua_pushnil(L); /* "result" to be removed */
508 return 0; /* read fails */
509 }
510}
511
512
513static int test_eof (lua_State *L, FILE *f) {

Callers 1

g_readFunction · 0.70

Calls 4

test2Function · 0.70
readdigitsFunction · 0.70
lua_stringtonumberFunction · 0.70
lua_pushnilFunction · 0.70

Tested by

no test coverage detected