From 68ee518e816c87dbb376dc38d11d1b47dfe2b53e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 1 Jul 2002 16:31:10 -0300 Subject: only tables need `lua_number2int' --- ltable.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ltable.c') diff --git a/ltable.c b/ltable.c index faae28cf..ba0919f3 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 1.110 2002/06/13 13:39:55 roberto Exp roberto $ +** $Id: ltable.c,v 1.111 2002/06/24 20:18:38 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -46,8 +46,11 @@ #define toobig(x) ((((x)-1) >> MAXBITS) != 0) +/* function to convert a lua_Number to int (with any rounding method) */ +#ifndef lua_number2int +#define lua_number2int(i,n) ((i)=(int)(n)) +#endif -#define TagDefault LUA_TTABLE #define hashnum(t,n) \ @@ -68,8 +71,11 @@ */ Node *luaH_mainposition (const Table *t, const TObject *key) { switch (ttype(key)) { - case LUA_TNUMBER: - return hashnum(t, nvalue(key)); + case LUA_TNUMBER: { + int ikey; + lua_number2int(ikey, nvalue(key)); + return hashnum(t, ikey); + } case LUA_TSTRING: return hashstr(t, tsvalue(key)); case LUA_TBOOLEAN: -- cgit v1.2.3-55-g6feb