lua-users home
lua-l archive

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


Should a module that uses FFI (but is intended to be used by
"FFI-blind" code) ever expose actual FFI-bound functions directly, or
should it instead wrap them in Lua functions?

The reason I ask is that it seems to me there are a couple of reasons
that you cannot trust FFI-bound functions to be passed around as
first-class values to arbitrary, "FFI-blind" code:
1. type(func) will be 'cdata', not 'function'. (of course, values that
try to make use of the __call metamethod already have similar
problems...)
2. Perhaps more seriously, == or ~= comparisons that involve an FFI
function are very likely to throw an "invalid comparison" error, which
FFI-blind code will not be expecting.

...and maybe more that I haven't thought of. What do people think
about this? I am quite keen that only code that directly deals with
FFI should have to know any of the details of it, so this kind of
thing seems important.

-Duncan