Re: how to get an out argument of type char*

  • From: Evan Wies <evan@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 18 Nov 2014 18:11:27 -0500

Marcelo,

You need to create (and manage the lifetime of) your buffers -- you can use ffi.new or you can also use memory allocators like malloc (if you have ffi.cdef'd malloc). You then can pass that buffer to recv. You can then examine the contents of the buffer using the index operator [] (note it is 0-based not 1-based in this context), or manipulate it using other functions like memcpy.

The luajit-nanomsg binding has a wrapper for nn_recv [1] and [2] is example of creating a buffer with ffi.new

[1] https://github.com/nanomsg/luajit-nanomsg/blob/master/nanomsg-ffi.lua#L233 [2] https://github.com/nanomsg/luajit-nanomsg/blob/master/examples/echo_client.lua#L33

Regards,
Evan

On 11/18/14 5:21 PM, marcelo nicolet wrote:
Suppose a function like recv( sock, buf, buflen, flags ), which puts the bytes from the socket buffers in the buf argument.

What kind of thing must be passed to such function?

Needless to say, I'm a newbie to LuaJIT, but it rocks!

TIA



Other related posts: