ruby / fiddle

A libffi wrapper for Ruby.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If the nested structure is an array of structures

kojix2 opened this issue · comments

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;

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

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