views:

101

answers:

1

Does Lua make use of 64-bit integers? How do I use it?

+7  A: 

Compile it yourself. Lua uses double-precision floating point numbers by default. However, this can be changed in the source (luaconf.h, look for LUA_NUMBER).

Joey
To clarify, Lua has a single numerical data type. By default this is a `double`, but can be changed in the header files to another type, such as `int64_t`.
Yann Ramin
If you change the number type in `luaconf.h`, don't forget to change the related macros accordingly.
lhf
@lhf: It's documented right above the macro, though, so I thought it'd be pretty discoverable.
Joey
Note that this will have some sweeping side effects, since this is the only type numbers will have. For example, `math.sin` is not necessarily sensible with an integral type for LUA_NUMBER. There is a patch to the Lua sources, known as the LNUM patch, which can mitigate this by supporting an integral type alongside a floating point type. See http://stackoverflow.com/questions/945731/what-is-the-maximum-value-of-a-number-in-lua/947763#947763
RBerteig
I am making an apps to use at the pge lua game engine on the psp. I was thinking to define the type of the variable, just as in VB.NET or C#.
Aaron de Windt
@Aaron: There is only a single numerical type and even with the LNUM patch RBerteig mentioned that doesn't change from the programmer's point of view – you just suddenly have 64-bit integers alongside with doubles and as far as I understood it choosing the correct type will be done automatically. You don't declare types in Lua as you do in VB or C# – those languages use a completely different typing discipline.
Joey