jmckaskill / luaffi

Standalone FFI library for calling C functions from lua. Compatible with the luajit FFI interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

casting between numbers and pointers

justincormack opened this issue · comments

in luajit the ffi can cast numbers to and from pointers.

eg S.cast("char *", 1) gives a pointer to memory location 1
and I can use
ffi.cast("long", ret) == -1
to test the return value from mmap.

I can't work out how to do either of those with luaffi, so I can't get mmap to work for ljsyscall.

You should be able to cast via uintptr_t for the moment, but the cast rules are indeed a bit strict atm.

ffi.cast('long', ffi.cast('uintptr_t', ret))

Hmm does (long) ptr even work on 64bit systems where long is 32 bit (e.g. win64)?

this code only runs on Linux...

Oh I realize that, I'm just wondering about the validity of allowing ffi.cast('int', ptr) in the general case. It seems that msvc doesn't mind (int) ptr so I'll just chop the pointer if the target int type is smaller.