Hacker News new | past | comments | ask | show | jobs | submit login
“Lua has no integer type, as it does not need it” (lua.org)
2 points by optimalsolver on May 19, 2021 | hide | past | favorite | 3 comments



For comparison, Julia allows packages such as BitIntegers.jl [1] to define integer types (like a 256 bit integer) that are treated the same as native types.

[1] https://github.com/rfourquet/BitIntegers.jl


The cited version of Programming in Lua was written for Lua 5.0 and published in 2003. Lua 5.3, released 2015, complemented the floating point type with a 64-bit integer type, which is much more ergonomic for 1) bit manipulation and 2) interfacing with 64-bit integer types in C.

Also, because of Lua's emphasis on embedding, the arithmetic type in Lua has long been customizable using compile-time preprocessor definitions. Prior to Lua 5.3 it was common for embedded environments to use an integer type for all arithmetic operations. Nothing in the core language requires floating point types, and the VM is carefully written to be agnostic to arithmetic type.

Part of Lua's original focus was programming pedagogy, and it was and remains a common argument in that niche that floating point is more than adequate. Lua predates JavaScript, and of course JavaScript lacked a primitive integer type for the same reason. (JavaScript might always lack one--a primitive integer type--because of the ubiquitous use of NaN tagging in the major implementations.) Lua just held more steadfastly to that view a little longer than some of its contemporaries. It might have stayed that way, too, if the width of floating point types had grown to accommodate larger integer types. (That is, if ABIs with 64-bit integer types also included an 80- or 128-bit floating point type.)


I disagree. The lack of an integer type means that you cannot deal with 64-bit integers properly. JavaScript also didn't used to have an integer type, although now it does, and it can have as many bits as you want to have, which is useful for some applications.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: