new function 'tointeger' + 'luaV_arith' replaced by 'luaT_trybinTM'

This commit is contained in:
Roberto Ierusalimschy
2013-04-29 14:12:50 -03:00
parent 8fff05f6d0
commit 88bf2f83c0
4 changed files with 70 additions and 100 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: ltable.c,v 2.73 2013/04/15 15:44:46 roberto Exp roberto $
** $Id: ltable.c,v 2.74 2013/04/26 15:39:25 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -123,17 +123,6 @@ static Node *mainposition (const Table *t, const TValue *key) {
}
static int numisint (lua_Number n, lua_Integer *p) {
lua_Integer k;
lua_number2integer(k, n);
if (luai_numeq(cast_num(k), n)) { /* 'k' is int? */
*p = k;
return 1;
}
return 0;
}
/*
** returns the index for `key' if `key' is an appropriate key to live in
** the array part of the table, -1 otherwise.
@@ -423,7 +412,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
lua_Integer k;
if (luai_numisnan(L, n))
luaG_runerror(L, "table index is NaN");
if (numisint(n, &k)) { /* index is int? */
if (luaV_numtointeger(n, &k)) { /* index is int? */
setivalue(&aux, k);
key = &aux; /* insert it as an integer */
}
@@ -505,7 +494,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
case LUA_TNIL: return luaO_nilobject;
case LUA_TNUMFLT: {
lua_Integer k;
if (numisint(fltvalue(key), &k)) /* index is int? */
if (luaV_numtointeger(fltvalue(key), &k)) /* index is int? */
return luaH_getint(t, k); /* use specialized version */
/* else go through */
}