lua-users home
lua-l archive

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


Hi all,

I have seen that there are already a few posts on that subject on the list archives, however I did not find a conclusion.

The fact is that the function lua_number2integer has a behavior which is really too random, depending on which platform lua is running. The header of the macro specify indeed that the rounding method is not defined. In my opinion this lead to an unacceptable portability issue.

Here is the code which revealed the unconsistency of the number to integer process:

    string.char(112+remaining/256, remaining%256)

where remaining was taken from 0 to 4095.


This code was done assuming that the string.char function was "correctly truncating" the value as C would do it in such a case.

To enlight the problem:
Here is what I get on Ubuntu 8.04 32 bits:
Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
> = string.char(72)
H
> = string.char(73)
I
> = string.char(72.1)
H
> =  string.char(72.5)
H
> = string.char(72.51)
I
> = string.char(72.5001)
H
>
Here is what I get on Windows XP 32 bits, (lua compiled with MSVC)
Lua 5.1.3  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> = string.char(72)
H
> = string.char(73)
I
> = string.char(72.1)
H
> =  string.char(72.5)
H
> = string.char(72.51)
I
> = string.char(72.5001)
I
>

Any comments ?

Regards,

Cuero
--

Anyware Technologies
Cuero Bugot

cuero.bugot@anyware-tech.com
Tel : +33(0)5 61 00 06 53
Fax : +33(0)5 61 00 51 46
 
Nouvelle adresse
Anyware Technologies
Lake Park
ZAC de l'Hers - Allée du Lac
Bâtiment A - Rdc - BP 87216
31672 Labège Cedex
France
www.anyware-tech.com