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
2010-06-23 19:15:46
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
2010-06-23 19:18:44
If you change the number type in `luaconf.h`, don't forget to change the related macros accordingly.
lhf
2010-06-23 21:44:40
@lhf: It's documented right above the macro, though, so I thought it'd be pretty discoverable.
Joey
2010-06-23 22:17:47
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
2010-06-24 00:15:04
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
2010-06-24 00:34:01
@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
2010-06-24 07:23:03