lua-users home
lua-l archive

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


On Jun 24, 2014, at 8:20 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> 
> To be honest, we never thought much about that. Integers first entered
> Lua through the C API (lua_pushinteger, lua_tointeger), and we followed
> C in truncating floats when doing the conversion. (It was also cheaper,
> which was important because such conversions were quite common.) But
> the question is quite pertinent: is this useful at all? If a program
> specifices 3.2 as a character index in a string, is it useful to
> silently truncate that to 3? Or maybe it would be better to throw an
> error in that case?  In the rare cases that the programmer really wants
> to truncate, that probably should be done explicitly.
> 

If Lua starts to do that, then the integer “sub-type” is starting to look more and more like a first-class type to me. I think it also becomes important to distinguish between “integral value” and “integer sub-type”, since these are subtly different (integers yield integer results for arithmetic, integral values, regardless of float/integer representation, can be used for string indexing etc).

—Tim