How do I specify a struct as the return value of a function in RubyFFI?

前端 未结 1 477
忘掉有多难
忘掉有多难 2021-01-13 15:22

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

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

相关标签:
1条回答
  • 2021-01-13 16:03
    class SOME_STRUCT < FFI::Struct 
        layout :a, :float, 
               :b, :float
    end
    

    and then

    attach_function 'fn_name', [], SOME_STRUCT
    

    and if it stack-allocated struct:

    typedef struct
    { 
        float a, b; 
    } SOME_STRUCT;
    

    you should use this:

    attach_function 'fn_name', [], SOME_STRUCT.by_value
    
    0 讨论(0)
提交回复
热议问题