Wireshark-bugs: [Wireshark-bugs] [Bug 9162] Lua does not appear to treat 64-bit values as number
Date: Wed, 18 Sep 2013 02:15:52 +0000

Comment # 1 on bug 9162 from
To quote the Lua 5.1 manual:

    http://www.lua.org/manual/5.1/manual.html#2.2

"*Number* represents real (double-precision floating-point) numbers. (It is
easy to build Lua interpreters that use other internal representations for
numbers, such as single-precision float or long integers; see file luaconf.h.)"

On most if not all the platforms on which Wireshark runs, double-precision
floating-point numbers have 52 bits of precision; 52 < 64.

So the answer to the question

    "Is Lua 5.1 an inappropriate language for writing code that needs to handle
64-bit integral values?"

is "yes", as there's no guarantee that Lua implementations *can* handle them. 
Wireshark *could* bundle its own version of Lua that uses "long integers",
although that might only give you 64-bit integers on 64-bit UN*X (not 32-bit
UN*X and not Windows, as "long" is 32 bits on those platforms).  I'm not sure
whether the Lua interpreter could be built to use 64-bit integers on all those
platforms.  (And, no, there's no guarantee that "long double" would have 64 or
more bits of precision; at least according to

    http://comments.gmane.org/gmane.comp.lang.lua.general/71926

it might not do so with Microsoft's C compiler on Windows.)

More importantly, doing so would mean that Lua couldn't handle *floating-point*
numbers, which might break *other* Lua code used with Wireshark.  It would also
be a major pain on systems where Lua is "part of the system" rather than being
bundled with Wireshark.

The "Numbers" patch:

    http://luaforge.net/docman/214/1270/README

would handle that, but would still mean that Wireshark, even on, say, most
Linux distributions, would have to bundle its own version of Lua.

The same applies to Lua 5.2:

    http://www.lua.org/manual/5.2/manual.html#2.1

"*Number* represents real (double-precision floating-point) numbers. Operations
on numbers follow the same rules of the underlying C implementation, which, in
turn, usually follows the IEEE 754 standard. (It is easy to build Lua
interpreters that use other internal representations for numbers, such as
single-precision floats or long integers; see file luaconf.h.)"

Lua 5.3, however, is a different matter:

    http://www.lua.org/work/doc/manual.html

"*Number* represents both integer numbers and real (floating-point) numbers.
Standard Lua uses 64-bit integers and double-precision floats, but it is easy
to compile Lua so that it uses 32-bit integers and single-precision floats."

When 5.3 comes out, we could bundle Wireshark with 5.3 on Windows and OS X.
possibly after updating it to be able to use 5.3 if necessary.  That would also
mean that *if* pick-your-Linux-distribution bundles Lua 5.3, or
pick-your-favorite-BSD has Lua 5.3 as the default Lua in its
{ports,packages,whatever} library, and so on, those platforms would also pick
up 5.3.


You are receiving this mail because:
  • You are watching all bug changes.