diff options
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 2.131 2018/01/28 15:13:26 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.132 2018/02/19 20:06:56 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -559,12 +559,13 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | |||
559 | TValue aux; | 559 | TValue aux; |
560 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); | 560 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); |
561 | else if (ttisfloat(key)) { | 561 | else if (ttisfloat(key)) { |
562 | lua_Number f = fltvalue(key); | ||
562 | lua_Integer k; | 563 | lua_Integer k; |
563 | if (luaV_flttointeger(key, &k, 0)) { /* does index fit in an integer? */ | 564 | if (luaV_flttointeger(f, &k, 0)) { /* does key fit in an integer? */ |
564 | setivalue(&aux, k); | 565 | setivalue(&aux, k); |
565 | key = &aux; /* insert it as an integer */ | 566 | key = &aux; /* insert it as an integer */ |
566 | } | 567 | } |
567 | else if (luai_numisnan(fltvalue(key))) | 568 | else if (luai_numisnan(f)) |
568 | luaG_runerror(L, "table index is NaN"); | 569 | luaG_runerror(L, "table index is NaN"); |
569 | } | 570 | } |
570 | mp = mainpositionTV(t, key); | 571 | mp = mainpositionTV(t, key); |
@@ -669,7 +670,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { | |||
669 | case LUA_TNIL: return luaO_nilobject; | 670 | case LUA_TNIL: return luaO_nilobject; |
670 | case LUA_TNUMFLT: { | 671 | case LUA_TNUMFLT: { |
671 | lua_Integer k; | 672 | lua_Integer k; |
672 | if (luaV_flttointeger(key, &k, 0)) /* index is an integral? */ | 673 | if (luaV_flttointeger(fltvalue(key), &k, 0)) /* index is an integral? */ |
673 | return luaH_getint(t, k); /* use specialized version */ | 674 | return luaH_getint(t, k); /* use specialized version */ |
674 | /* else... */ | 675 | /* else... */ |
675 | } /* FALLTHROUGH */ | 676 | } /* FALLTHROUGH */ |