How to specify structure as function return value in RubyFFI?

I need to load several functions that return structures from the library itself.

attach_function 'fn_name', [], # ... What do I put here? 

The Wiki RubyFFI pages seem outdated, so I got a little lost here.

How to create FFI::Struct , and how can I specify it as a return type of my own function?

+4
source share
1 answer
 class SOME_STRUCT < FFI::Struct layout :a, :float, :b, :float end 

and then

 attach_function 'fn_name', [], SOME_STRUCT 

and if it contains a stack:

 typedef struct { float a, b; } SOME_STRUCT; 

you should use this:

 attach_function 'fn_name', [], SOME_STRUCT.by_value 
+8
source

Source: https://habr.com/ru/post/1344518/


All Articles