Re: bit.band() with uint64_t

  • From: madigest i <madigest@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sat, 9 Mar 2013 06:16:21 +0200

Mike Pall <mike-1303@xxxxxxxxxx> kirjoitti 8.maalis.2013 kello 11.31:
> 
>> local returnValue64 = ffi.new("uint64_t")
>> returnValue64 = timevalueX --from system call
> 
> Ouch. In Lua, variables are names for values and not containers.
> Values carry types.
> 
> The first assignment is nonsense here -- one cannot force a
> variable type in Lua, no matter how. The second assignment simply
> points the variable to another value and *that* decides the type.

Actually I knew it, badly formulated mail.

> [I don't think it's a good idea to start with the FFI, unless one
> has a firm grasp of Lua's semantics.]

Well, I have to start from somewhere. I have had a great success moving my old 
(and new) C-code to ffi. I find it easier to write ffi code than plain C.

> 
>> - Trouble is that bit.band() does not accept int64_t or uint64_t.
> 
> This functionality will be added soon to v2.1.


Thanks, great.


After spending few hours with ffi.cast, ffi.copy and math I have a question:

In Lua 0x001fffffffffffff is the biggest value that does not change when 
converting to Lua double with 'tonumber(0x001fffffffffffff)' (so that lower 
bits do not change).

If I get for ex. 0xba5fffffffffffa1 I need to convert it to 0x001fffffffffffa1 
so that I get the full precision in the low end. Big numbers do not matter but 
small numbers must be correct. This is trivial in C, but how to do it in Lua?

Because this is inside timer function it must be fast. Is it possible without 
string manipulation? 

I can easily wait for 2.1, timers do not matter until my program is ready.

--
Regards,

Pasi Mankinen
Finland




Other related posts: