Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Automatic casting of lua file handles, #37

Open
daurnimator opened this issue Jun 3, 2012 · 1 comment
Open

Automatic casting of lua file handles, #37

daurnimator opened this issue Jun 3, 2012 · 1 comment

Comments

@daurnimator
Copy link

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().
@jmckaskill
Copy link
Owner

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants