by curun1r · 12y ago · 0 comments
fs.readFile(filename, function(err, data)
-- remember to check err
end)
With this binding the code would look like: local data = fs.readfile(filename)
-- err was raised if one occurred
With coroutines, you can use exceptions and for/while loops and they continue to work as you would expect.Here we have a FFI-binding which means that only the header of the C functions are sufficient for the ffi library to handle all conversions of variables to and from the lua environment. Additional interface related functions are coded in lua instead of C.
Luajit provides a powerful FFI implementation which makes it very easy to provide interfaces to C libraries. However, it is not part of the vanilla lua implementation which is why both versions have their reasons to exist.