Consider the following two FFI structs:
class A < FFI::Struct
layout :data, :int
end
class B < FFI::Struct
layout :nested, A
end
To instantiate them:
a = A.new
b = B.new
Now when I try to assign a
to b.nested
like this:
b[:nested] = a
I get the following error:
ArgumentError: put not supported for FFI::StructByValue
It seems FFI doesn't allow you to assign using the [] syntax if the nested struct is "nested by value", that is it is not a pointer. If so, how do I then assign a
to b.nested
?
When you use FFI to nest it can work like this:
The FFI "b" object has created its own "a" object; you don't need to create your own.
What it looks like you're trying to do is create your own "a" object then store it:
A solution is to store "a" as a pointer: