RE: Access to parameterized type

  • From: William Adams <william_a_adams@xxxxxxx>
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Sat, 1 Sep 2012 16:19:22 -0700

Perfect.  Thanks.
________________________________
From: Mike Pall
Sent: 9/1/2012 3:15 PM
To: luajit@xxxxxxxxxxxxx
Subject: Re: Access to parameterized type

William Adams wrote:
> I have need to access the type of the parameter used to construct a 
> parameterized structure:
>       local Vector = ffi.typeof("struct { int n; int Capacity; $ *Data; }", 
> ct);
> Is there any way to get at what 'ct' was from within a metamethod?
> I can find out how large it is by doing ffi.sizeof(instance.Data[0])
> but, all I get out of ffi.typeof(instance.Data) is "struct 102".
> Alternative, could I use "struct 102" in any meaningful way, like 
> ffi.new("struct 102", 100);

ffi.new() takes a cdecl (a string), a ctype object or a cdata
object. So just use ffi.new(instance.Data[0], ...).

--Mike

Other related posts: