Re: Access to parameterized type

  • From: Mike Pall <mike-1209@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sun, 2 Sep 2012 00:15:39 +0200

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: