Re: Cost of wrapping ffi functions

  • From: Duncan Cross <duncan.cross@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 6 Jun 2012 16:25:24 +0100

On Wed, Jun 6, 2012 at 4:00 PM, Mike Pall <mike-1206@xxxxxxxxxx> wrote:
> Tim Caswell wrote:
>> But I want to wrap some functions that are hairy to deal with
>> (outargs, strings, structs -> tables, etc..)  Is the best way to
>> accomplish this to wrap in a lua function and use the closure to the
>> gles object?
>>
>>   local function glViewport(x, y, width, height)
>>     gles.glViewport(x, y, width, height)
>>   end
>
> If the wrapper actually performs something (e.g. translating
> outargs into extra results), then the above pattern is the best
> way to do it.
>
> But if the wrapper function really does nothing, then it's kind of
> pointless. You might as well pass the C function pointer.

I think this is especially true now that C values never throw an error
when you compare them to unrelated types. Before that I would been
wary of allowing C function pointers through into "FFI-ignorant" code,
that may want to use these functions as first-class values in
arbitrary ways. So, thanks again for making that decision. :-)

-Duncan

Other related posts: