On 19/04/16 16:25, Elizabeth Mattijsen wrote:
I’ve been looking at nativecast, but haven’t been able to find an > example
that I could apply to this?
>
Liz
Right! I should have given a working example, or at least mention that
CArray would probably be necessary to make this work.
Here's one to go from a num to an int:
perl6 -e 'use NativeCall; my CArray[num64] $foo .= new(1234e9); say
nativecast(CArray[int64], $foo)[0].fmt("0x%x")'
0x4271f5021b400000
And if you want the bytes directly, as if in a buffer, you'd probably do
something like
perl6 -e 'use NativeCall; my CArray[num64] $foo .= new(1234e9); say
Buf[uint8].new(nativecast(CArray[uint8], $foo)[^8])'
Buf[uint8]:0x<00 00 40 1b 02 f5 71 42>
Hope that helps!
- Timo