Skip to content

Nested struct (rock) and pass-by-value (hard place) issue. #14

@jbarrett

Description

@jbarrett

I was planning to do some persistence trickery by doing my drawing onto a RenderTexture, which is a nested struct...

package Raylib::FFI::RenderTexture {
use FFI::Platypus::Record qw( record_layout_1 );
record_layout_1(
$ffi,
uint => 'id',
opaque => 'texture', # cast to Texture
opaque => 'depth', # cast to Texture
);
}
$ffi->type( 'record(Raylib::FFI::RenderTexture)' => 'RenderTexture' );
$ffi->type( 'RenderTexture' => 'RenderTexture2D' );

...that is, its members are not struct pointers, which would be nice and handy, they are stuffed into this struct, so instantiating one (via LoadRenderTexture()) segfaults.

My next thought was to use a FFI::C::Struct, which does support nested structs, but FFI::C objects must be passed into C via FFI::Platypus by pointers - pass-by-value is not supported. Raylib uses pass-by-value.

I don't have any solid ideas to resolve this right now - if I did this would be a pull request. So...

  1. Replace the opaques with a type big enough to hold the structs (getting this to align/cast right would be ... "challenging")?
  2. Bundle a slew of wrapper functions which do pass-by-reference for structs?
  3. Add nested struct support to record or pass-by-value support to FFI::C
  4. Look at other tech (Affix? or something called "XS"?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions