ruby/fiddle

If the nested structure is an array of structures

kojix2 opened this issue · 2 comments

kojix2 commented

Fiddle supports nested structs.

require 'fiddle/import'

module FFI
  extend Fiddle::Importer

  Coord = struct [
    'float x',
    'float y',
    'float z'
  ]

  Triangle = struct [
    { 'vertices' => Coord },
    { 'normal' => Coord }
  ]
end

But what if the array of structures is nested?

require 'fiddle/import'

module FFI
  extend Fiddle::Importer

  Coord = struct [
    'float x',
    'float y',
    'float z'
  ]

  Triangle = struct [
    { 'vertices' => [Coord, 3] },
    { 'normal' => [Coord, 3] }
  ]
end

original C code:

typedef struct
{
  float x, y, z;
} gr3_coord_t;

typedef struct
{
  gr3_coord_t vertex[3];
  gr3_coord_t normal[3];
} gr3_triangle_t;
kou commented

Could you try the following?

require 'fiddle/import'

module FFI
  extend Fiddle::Importer

  Coord = struct [
    'float x',
    'float y',
    'float z'
  ]

  Triangle = struct [
    { 'vertices[3]' => Coord },
    { 'normal[3]' => Coord }
  ]
end
kojix2 commented

Sorry for the late reply.
I will use this code. Thank you very much.