|
For example, passing the value 37, the Lua layer receives 5.3265215697135e-315Hello,I'm getting a strange behavior using the functions lua_pushinteger and lua_pushunsigned.When calling these functions, the value stored in the Lua stack L is not the value passed to the function (an integer), actually It is a small float number.It seems there is some sort of error converting values as all Lua numbers are stored as double numbers.I'm using lua 5.2, gcc 4.3.4, building for ARM processors, 32 bits words.
I'm passing the compile flag LUA_COMPAT_ALL and LUA_ANSIThe code I'm using is something like this:
int GetShiftNumber(lua_State *L)
{
lua_pushinteger(L, gsConfig.ShiftNumber);
#ifdef RUNLOG2
sprintf(NurLogBuf, "GetShiftNumber: shiftno = %lu", gsConfig.ShiftNumber);
Log2(NurLogBuf);
#endif
return(1);
}The Log2 just logs the values on the RS232 port.The Lua code that invokes the C code above is:
if (lua_type == 'transaction') then
shiftno = tran.getshiftno()
dev.log('ShiftNumber: ' .. shiftno)
tran.print('ShiftNumber: ' .. shiftno)
endThe tran.getshiftno is the corresponding Lua function for the above GetShiftNumber.The dev.log function just invokes the C Log2 function.On the C layer, the variables are correct displayed:
GetShiftNumber: shiftno = 37On the Lua layer, the shiftno is incorrect, dev.log displays:
ShiftNumber 5.3265215697135e-315The gsConfig is a global structure and the field gsConfig.ShiftNumber is an unsigned long.I also tried to use the lua_pushunsigned and got the same result.Then I created a local int variable, did and explicit cast and passed the local variable to lua_pushinteger but nothing changed.Passing values from Lua layer to C layer works fine.The same code, works fine in other platforms.Could you help me to find a solution for this issue?Thank you in advance.Paulo Roberto Brandão.