/* ** this function is quite liberal in what it accepts, as 'luaO_str2num' ** will reject ill-formed numerals. */ static int read_numeral (LexState *ls, SemInfo *seminfo) { TValue obj; const char *expo = "Ee"; int first = ls->current; lua_assert(lisdigit(ls->current)); save_and_next(ls); if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */ expo = "Pp"; for (;;) { if (check_next2(ls, expo)) /* exponent part? */ check_next2(ls, "-+"); /* optional exponent sign */ if (lisxdigit(ls->current)) save_and_next(ls); else if (ls->current == '.') save_and_next(ls); else break; } save(ls, '\0'); buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ if (!buff2num(ls->buff, &obj)) /* format error? */ trydecpoint(ls, &obj); /* try to update decimal point separator */ if (ttisinteger(&obj)) { seminfo->i = ivalue(&obj); return TK_INT; } else { lua_assert(ttisfloat(&obj)); seminfo->r = fltvalue(&obj); return TK_FLT; } }
/* ** this function is quite liberal in what it accepts, as 'luaO_str2num' ** will reject ill-formed numerals. */ static int read_numeral (LexState *ls, SemInfo *seminfo) { TValue obj; const char *expo = "Ee"; int first = ls->current; lua_assert(lisdigit(ls->current)); save_and_next(ls); if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */ expo = "Pp"; for (;;) { if (check_next2(ls, expo)) /* exponent part? */ check_next2(ls, "-+"); /* optional exponent sign */ if (lisxdigit(ls->current)) save_and_next(ls); else if (ls->current == '.') save_and_next(ls); else break; } save(ls, '\0'); if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ lexerror(ls, "malformed number", TK_FLT); if (ttisinteger(&obj)) { seminfo->i = ivalue(&obj); return TK_INT; } else { lua_assert(ttisfloat(&obj)); seminfo->r = fltvalue(&obj); return TK_FLT; } }
int check_next(char **tetri) { int i; int j; int valid; i = 0; valid = 0; while (i < 4) { j = 0; while (j < 4) { if (tetri[i][j] == '#') { if (j < 3 && tetri[i][j + 1] == '#') valid++; if (i < 3 && tetri[i + 1][j] == '#') valid++; } j++; } i++; } if ((valid = valid + check_next2(tetri)) < 5) return (0); return (1); }
static int read_numeral (LexState *ls, SemInfo *seminfo) { TValue obj; int first = ls->current; lua_assert(lisdigit(ls->current)); save_and_next(ls); if (first == '0') check_next2(ls, "xX"); /* hexadecimal? */ for (;;) { if (lisxdigit(ls->current)) save_and_next(ls); else break; } save(ls, '\0'); if (!buff2num(ls->buff, &obj)) /* format error? */ lexerror(ls, "malformed number", TK_INT); lua_assert(ttisinteger(&obj)); seminfo->i = ivalue(&obj); return TK_INT; }