Reputation: 8315
The Lua documentation says that Lua represents values of type number using a double, which allows all long integer values to be correctly represented using a floating point number.
However I see in the code that lua_Number is actually a float. Which is giving me the following warning :
warning C4244: 'argument' : conversion from 'double' to 'lua_Number', possible loss of data
For :
double fVarVal = 0.0;
lua_pushnumber( L, fVarVal );
So how are the values of type number represented in Lua ? float or double ? If they are using floats, can't this create problems when integer values, like array indexes, are being used ?
I'm using Lua 5.3.2 for Windows CE.
Upvotes: 5
Views: 11585
Reputation: 473447
I'm using Lua 5.3.2 for Windows.
Well that rather changes things. Lua 5.3 added the ability to use actual integers in Lua, directly. Lua always had the lua_pushinteger
function, but in 5.3, it doesn't convert it to a double
. It is instead a 64-bit integer.
From Lua of course, integers and floats look the same. And most of the Lua C API doesn't make much distinction. But it can if you want it to.
In any case, lua_Number
defaults to double
, so even on Lua 5.1/2, integers-as-floats was not much of a problem. Of course, lua_Integer
and lua_Number
can be adjusted as you see fit. Just be aware that external DLLs you use have to be recompiled with those settings too.
Upvotes: 2