c++ - How do I get outputs in Ruby using SWIG over a C function taking pointers to output arguments? -


how outputs (declared using int pointers) function wrote in c++, using swig, in ruby? in transcript below, i'm declaring 'a' , 'b' them initialized integers, they're supposed outputs.

irb(main):001:0> require 'vetms.rb' => true irb(main):002:0> a=3 => 3 irb(main):003:0> b=4 => 4 irb(main):004:0> $v.button a, b argumenterror: wrong arguments overloaded method 'baseinterface.button'. possible c/c++ prototypes are: bool baseinterface.button(int *id, int *event) bool baseinterface.button(int *id) bool baseinterface.button()      (irb):4:in `button'     (irb):4     :0 

(edit) swig code isn't remarkable--i use %include 'pointers.i' i'm not sure that. 'vetms.rb' requires generated library , creates $v object. main problem here c++ function, ruby can't bind 'a' , 'b' objects to:

bool baseinterface.button(int *id, int *event) 

my problem is, if doing in straight c, pass address of 'a' , 'b' function, , function set contents--'a' , 'b' output variables. i'd call '$v.button a, b' same thing. i'm not sure passing variables reference or address concept in ruby, need 2 outputs call, , don't know how achieve it.

the swig docs suggest can have such function (this in "swig , ruby", section 32.3.5 pointers):

foo *get_foo(); void set_foo(foo *foo); 

but provide 1 usage example, return value:

irb(main):001:0> foo = example::get_foo() #<swig::type_p_foo:0x402b1654> 

in case, how 1 use "set_foo" in ruby?

i'll ffi, know how swig?

hard comment without swig / vetms.rb code. guessing need work typemaps.

i'd suggest using ffi instead of swig interface c code

https://github.com/ffi/ffi

much easier, , nicer


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -