In the book, working with this function is described like this:
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int creat (const char *name, mode_t mode) However, when running in lua code
ffi = require 'ffi' ffi.cdef [[int creat (const char *name, mode_t mode)]] An error occurs:
stdin:1: unknown type mode_t on line 1 stack traceback: [C]: in function 'cdef' stdin:1: in main chunk [C]: in ? Apparently, the problem arises from the fact that the type is not described with #include . How can this problem be solved?
UPD : following the advice to use lcpp came to this lcpp :
> lcpp = require("lcpp") > ffi = require("ffi") > ffi.cdef[[ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int creat (const char *name, mode_t mode) ]] stack traceback: /home/v/.luarocks/share/lua/5.2/lcpp.lua:232: in function 'error' /home/v/.luarocks/share/lua/5.2/lcpp.lua:1382: in function 'compileFile' /home/v/.luarocks/share/lua/5.2/lcpp.lua:746: in function </home/v/.luarocks/share/lua/5.2/lcpp.lua:745> (...tail calls...) /home/v/.luarocks/share/lua/5.2/lcpp.lua:735: in function '_doWork' /home/v/.luarocks/share/lua/5.2/lcpp.lua:742: in function </home/v/.luarocks/share/lua/5.2/lcpp.lua:742> /home/v/.luarocks/share/lua/5.2/lcpp.lua:1367: /home/v/.luarocks/share/lua/5.2/lcpp.lua:232: lcpp ERR [0000] file not found: sys/types.h stack traceback: [C]: in function 'for iterator' /home/v/.luarocks/share/lua/5.2/lcpp.lua:1367: in function 'compile' /home/v/.luarocks/share/lua/5.2/lcpp.lua:1931: in function 'lcpp' /home/v/.luarocks/share/lua/5.2/lcpp.lua:1939: in function 'cdef' stdin:1: in main chunk [C]: in ?
ffi.cdef [[int creat (const char *name, mode_t mode]]way, your bracket is not closed:ffi.cdef [[int creat (const char *name, mode_t mode]]- aleksandr barakin