RE: how to send lua table to c/c++ by luajit.ffi ?

  • From: William Adams <william_a_adams@xxxxxxx>
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Wed, 27 Nov 2013 17:11:40 -0800

Also, you better be very mindful of the lifetime of those strings on the lua 
side.


Sent from my Windows Phone
________________________________
From: Ryan Gonzalez<mailto:rymg19@xxxxxxxxx>
Sent: ‎11/‎26/‎2013 7:21 PM
To: luajit@xxxxxxxxxxxxx<mailto:luajit@xxxxxxxxxxxxx>
Subject: Re: how to send lua table to c/c++ by luajit.ffi ?

I NEW something would be wrong! Like I said, it was untested, hence the
fact I made a stupid mistake.


On Tue, Nov 26, 2013 at 9:11 PM, Coda Highland <chighland@xxxxxxxxx> wrote:

> On Tue, Nov 26, 2013 at 7:06 PM, Ryan Gonzalez <rymg19@xxxxxxxxx> wrote:
> > I think you need this:
> >
> > ffi.cdef[[
> > typedef struct { char* a, b, c; } mystruct;
> > ]]
> >
> > mystruct = ffi.new("mystruct[?]", 3)
> > mystruct[0] = "a";
> > mystruct[1] = "b";
> > mystruct[2] = "c";
> >
> > Note that I quickly hacked this together, and it is UNTESTED!!!
>
> That should be "char *a, *b, *c;" or else you've defined a structure
> containing one string and two single characters.
>
> /s/ Adam
>
>


--
Ryan
When your hammer is C++, everything begins to look like a thumb.

Other related posts: