[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Getting the value of Lua's io.output() from the C API
- From: Peter Aronoff <telemachus@...>
- Date: Tue, 11 Dec 2012 12:03:23 -0500
Hi,
As a way of exploring the C API, I've been working on a C module to give
Lua an isatty(3) function. My thought was to allow users to call the method
in two ways:
isatty(filehandle) -- Returns true or false depending on whether the
filehandle refers to a tty
isatty() -- Checks whether the current value of io.output()
refers to a tty
Within Lua, io.output() with no explicit parameter returns the default
output file. I would like to have my isatty with no parameters *check* the
current output filehandle (whatever that is).
I thought of a way to call Lua from the C - get the io table and then call
the io.output() function with no parameters and push that return value back
onto the C stack. But it seems odd to write a C module that calls back to
Lua in this way.
However, I wasn't able to see a clear way to get at the value of "current
output file" from the C API. So, finally, my two questions:
1) Did I miss something? Does the C API expose the value of io.output()
somewhere?
2) As a general rule, is it ok (common, not bad form) to write
a C module that simultaneously provides a new function to Lua and
calls out to Lua to get information that the C API doesn't make easy
to get?
Sorry if this was long, and thanks in advance.
Peter
--
We have not been faced with the need to satisfy someone else's
requirements, and for this freedom we are grateful.
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System