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

Automatic casting of lua file handles,

daurnimator opened this issue · comments

Quoting Mike Pall:

I've added conversion of an io.* file handle to a FILE *. Actually
it converts to a void * because I don't want to expose a standard
'FILE' C type. But this doesn't matter as it converts to a FILE *
argument of a C function.

The changes have been pushed to git HEAD. Provided you add the
required C function declarations, you can do this now:

 ffi.C.fputs("test\n", io.stderr)
 ffi.C.fprintf(io.stderr, "Hello %s\n", "world")

 if ffi.abi("win") then
   print(ffi.C._fileno(io.stderr))    --> 2
 else
   print(ffi.C.fileno(io.stderr))     --> 2
 end

Ditto for any file handle you get from io.open() or io.popen().

Thanks for the report. This should be doable with Lua 5.2 as it now exposes a luaL_Stream.