I just tried to use *string.format* instead of using the operator *..* and it worked fine.
The new Lua code:
/if (lua_type == 'transaction') then
shiftno = tran.getshiftno()
dev.log(string.format('ShiftNumber: %d' , shiftno))
tran.print(string.format('ShiftNumber: %d' , shiftno))
end/
The question is: why the operator *..* does not work on this platform and works on Linux and others platforms I have here.
The Lua source code used to build the libraries were the same.
Thank you again.
Regards.
On Thu, May 7, 2015 at 11:50 AM, Paulo Roberto <betobrandao@gmail.com <mailto:betobrandao@gmail.com>> wrote:
Hello,
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.
For example, passing the value /37/, the Lua layer receives /5.3265215697135e-315/
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_ANSI/
The 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)
end
/
/
/
The/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 = 37/
On the Lua layer, the /shiftno/ is incorrect, /dev.log/ displays:
/ShiftNumber 5.3265215697135e-315/
The /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.