lua-users home
lua-l archive

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

Merick wrote:
> Jerome Vuarand wrote:
>> I think you can use struct.pack("i8",-1). But as you said you won't be
>> able to generate the whole range of 64bits integers since Lua numbers
>> are double (unless you have a custom built Lua version).
> I've actually tried that, but was still unable to get it to read the
> number correctly from FB. However, after considering what I'm going to
> be using this for I've realized that +/-9223372036854775807 (the largest
> number a longint can hold in FB) is a ridiculously large number that
> I'll probably never use in any of my projects so I should be able to get
> by without needing to use longints anyway.

Don't use 64-bit ints unless you absolutely need to. Most people
are still running 32-bit machines anyway. Better to stick to
normal 32-bit ints or keep it simple like Lua by using doubles.

struct.pack("i8",-1) won't work properly. Looking at the sources
of struct.c, the putinteger function operates on an unsigned long,
which is 32-bit in C.

You don't need Lua to test reading from FB. First use FB to read
and write and look at the binary data corresponding to the
numbers. For example, assuming little endian, 2 and -2 in 64-bit
int will give:

02 00 00 00-00 00 00 00

A hex editor would be useful. You can also write out strings
literally, like "\254\255\255\255\255\255\255\255". Then compare
the binary data generated by FB and the equivalent generated by
Lua. Try to solve your problem in smaller steps. Make sure the FB
side is working and you fully understand it before trying to
connect Lua to it.

Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia