Re: do function casts ever disappear?

  • From: Mike Pall <mike-1207@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sat, 21 Jul 2012 11:42:30 +0200

William Adams wrote:
> I'm holding onto the cast within the table, along with the key,
> which is the function name.  Is that sufficient to keep the cast
> around?

Yes. The result of that cast is just a cdata object holding a
function pointer. This object is anchored in a table, so it won't
go away.

You only have to take care not to unload the shared library that
contains the code for this function. You need to keep a reference
to the result of ffi.load(). Usually there are some Lua functions
around that anchor it in an upvalue, so this is less of a concern.

--Mike

Other related posts: