[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [LuaJIT FFI] Recommended policy for exposing FFI functions
- From: Duncan Cross <duncan.cross@...>
- Date: Sun, 31 Jul 2011 18:35:36 +0100
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