lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>What is required, though, is that the value supplied as a key be used as
>the key. A table should be indexable by both 2^31 and -2^31. In this
>case it is not. Hence the erroneous implementation and the need for a fix.
>

The table CAN be indexed by both of those indices, distinctly. The problem isn't that, it's that lua_rawgeti takes an integer instead of a lua_Number (perhaps that is a better fix? Though it would reduce performance significantly, I think). As a result, the number is cast to an integer and THEN we have issues beyond the bounds:

> t = {}; 
> t[2^31] = 1; 
> t[-2^31] = 2; 
> t[2^500] = 3; 
> for k,v in pairs(t) do print(k..[[:]]..v) end
2147483648:1
-2147483648:2
3.2733906078961e+150:3


Thus, table.insert has a problem as it uses lua_rawgeti, but accessing a table directly does not.

-- Matthew P. Del Buono