Using an enumeration for float->integer coercion modes

This commit is contained in:
Roberto Ierusalimschy
2019-12-05 14:14:29 -03:00
parent 2d92102dee
commit d30569c064
4 changed files with 30 additions and 22 deletions

View File

@@ -626,7 +626,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
else if (ttisfloat(key)) {
lua_Number f = fltvalue(key);
lua_Integer k;
if (luaV_flttointeger(f, &k, 0)) { /* does key fit in an integer? */
if (luaV_flttointeger(f, &k, F2Ieq)) { /* does key fit in an integer? */
setivalue(&aux, k);
key = &aux; /* insert it as an integer */
}
@@ -745,7 +745,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
case LUA_TNIL: return &absentkey;
case LUA_TNUMFLT: {
lua_Integer k;
if (luaV_flttointeger(fltvalue(key), &k, 0)) /* index is an integral? */
if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */
return luaH_getint(t, k); /* use specialized version */
/* else... */
} /* FALLTHROUGH */