Comment

Comment by epcoa

The LuaJIT example isn't correct though, the lifetime of garbage collected objects is clearly documented: https://luajit.org/ext_ffi_semantics.html#gc In the example function `blob` will not be collected because it is reachable from the `blob` argument local variable (IOW it is on the Lua stack). `ffi.string`() copies the string data into a new Lua string, and the lifetime of blob is guaranteed until the return of the function. So not sure what the issue is.

  function blob_contents(blob) -- <- this ensures liveness until past return 
     local len_out = ffi.new('unsigned int')
     local contents = hb.hb_blob_get_data(blob, len_out)
     local len = len_out[0];
     return ffi.string(contents, len)
  end
parent epcoa 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton