Reputation: 17312
I have a small C program that calls a Lua function and sends it a file descriptor, is it possible to write to this file descriptor from Lua ?
Upvotes: 3
Views: 1234
Reputation: 23
Have a look at the C function fdopen(). It takes a file descriptor and gives you back a stream/FILE*.
If you implement a Lua C extension for fdopen() to give you back a LuaStream then you can use the normal Lua io calls on the resulting Lua Stream.
Better than just implementing a one-off function for what you want to do.
see io_open in liolib.c of the Lua 5.2.1 sources for an example of creating a Lua Stream.
Upvotes: 2
Reputation: 17312
I think redirecting the standard output to the socket fd, before calling the lua function, may work, but it's easier to just return the string and write it in C.
Upvotes: -1