jmckaskill / luaffi

Standalone FFI library for calling C functions from lua. Compatible with the luajit FFI interface.
469 stars 84 forks source link

S.open in ljsyscall #28

Closed jmckaskill closed 12 years ago

jmckaskill commented 12 years ago

lua: unable to convert argument 2 from cdata to cdata

jmckaskill commented 12 years ago
lua: unable to convert argument 2 from cdata<int> to cdata<int64_t>
stack traceback:
   [C]: in function 'open'
    ./io/syscall.lua:2388: in function 'open'
justincormack commented 12 years ago

Minimal test case (I wrote ljsyscall, happy to get it to work with luaffi)


local ffi = require "ffi"

local C = ffi.C

ffi.cdef[[
typedef uint32_t mode_t;
int open(const char *pathname, int flags, mode_t mode);
]]

local int_t = ffi.typeof("int")

assert(ffi.C.open("/tmp/file/does/not/exist", int_t(1), 0))
justincormack commented 12 years ago

note I fixed this issue in ljsyscall, although it seems to be a bug. Working on other issues.

jmckaskill commented 12 years ago

Ah I see what's happening. I was wondering how he had managed to create a cdata because any access to an int is normally converted to a lua number.