lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks for your reply! I'm eager to learn more about the use of FFI.

However when I try to run your example I get the error: declaration specifier expected near 'FILE'



On 11/20/2011 05:20 PM, Francesco Abbate wrote:
I cannot resist to the temptations, this can be done so easily with
the FFI module :-)

local ffi = require('ffi')

ffi.cdef [[
   extern FILE *stdin;
   int isatty(int FILEDES);
   int fileno (FILE *STREAM);

function isatty()
    local fd = ffi.C.fileno(ffi.C.stdin)
    return ffi.C.isatty(fd)

Please note that the use of "fileno" can be avoided if you assume that
the file descriptor of stdin is 0. This is always true on linux.