Re: FFI, cURL and function callback

  • From: Szabó Antal <szabo.antal.92@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sun, 24 Mar 2013 17:12:47 +0100

2013/3/24 pingon begand <sbronfion@xxxxxxxxx>:
> The function callback is a memory sensitive task. Do you think something
> like this will work as expected? :
>
> -- global variable where I store the data
> data = ""
> function cb(ptr, size, nmemb, stream)
>         ffi.copy(data, ptr)
> end

You should add a third parameter to ffi.copy, the number of bytes to
copy (see: http://luajit.org/ext_ffi_api.html ). Otherwise I think
it's fine.
Also, note that C to lua callbacks are much slower than the rest of
the FFI, so avoid it if you want/need high performance.

Other related posts: