lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all,

I wrote my own Lua-crc function and got some weired results. For
proofing correctness I also implemented a c-program.
But when the c-program returned a negative value (with %d) I got a
different value from the Lua-library.

My algorithm is quite similar to the one from lash-lua:
http://code.google.com/p/lash-lua/source/browse/trunk/crc32.c?spec=svn5&r=5#112

Although I got the data with the luaL_checkinteger()-function.
Seems that there lies the problem, but I don't get what I've done wrong.
Inside Lua every number is a floating-point. So when I call my library
function from a Lua-script I pass the value converting it to a number.
Therefore a floatingpoint number should be on the stack and I "cast "
it into my c- integer variable with the check integer-function.
But representation of integer-values shouldn't be a problem
(http://lua-users.org/wiki/FloatingPoint).
In the c-program I pass the value via atoi()-function call from argv[]
which shouldn't be a problem, too.

Can anyone give me a hint, what I am missing.

Thanks
Matthias

-- 
motzblog.wordpress.com