# wxRuby / wxWigets with C++

**URL:** <https://www.ruby-forum.com/t/wxruby-wxwigets-with-c/135170>\
**Category:** wxRuby\
**Created:** [April 18, 2008, 6:55pm UTC](https://www.ruby-forum.com/t/wxruby-wxwigets-with-c/135170 "2008-04-18T18:55:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSSSSukasz\_SSSSapiS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@SSSSSukasz\_SSSSapiS](https://www.ruby-forum.com/u/SSSSSukasz_SSSSapiS)\
**Post date:** [April 18, 2008, 6:55pm UTC](https://www.ruby-forum.com/t/wxruby-wxwigets-with-c/135170/1 "2008-04-18T18:55:36Z")

</div>

Hi,

I am experimenting with integration of C++ and Ruby. What exactly I  
would  
like to do is to provide an option to use Ruby and wxRuby for creation  
of  
GUI and doing algorithms in C++ and then displaying results in the  
openGL  
Canvas.

I can easily use openGl / Glut in “render” function in C++ say class  
VisualiseGraph, build using SWIG an extention to Ruby and then use this  
function (that does not take any parameters and returns void) to display  
on the wxGLCanvas  
(  
@canvas.evt\_paint { @canvas.paint { render } }  
).

But I would also like to transfer the data from the form built using  
Ruby  
into some classes in C++. Like parameters: numbers and string. But I am  
wondering if it is possible to create controls in Ruby and then just  
assign then into C++ fields (the controls not values). For example

class FormInCpp  
{  
wxTextField \* someText;

void setSomeText(wxTextField \* param){  
someText = param;  
}

}

then use SWIG to build extention in module say Llap

and then

txt = Wx::TextCtrl.new(self, -1, “val”)

form = Llap::FormInCpp.new  
form.setSomeText(txt)

I thought these are in fact the same controls, they were written in C++,  
but I guess txt is not of type [wxTextField \*], but rather  
#SWIG::TYPE\_p\_wxTextCtrl:0xb7c49944  
so how to get the pointer to wxTextField so I can manipulate the  
control  
from cpp class like this

someText-\>GetValue()

and then do smthing with this value.

---

<div class="post-metadata">

**Author:** ![SSSSSukasz\_SSSSapiS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@SSSSSukasz\_SSSSapiS](https://www.ruby-forum.com/u/SSSSSukasz_SSSSapiS)\
**Post date:** [April 19, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/wxruby-wxwigets-with-c/135170/2 "2008-04-19T13:28:33Z")

</div>

£ukasz £apiñski wrote:

> I am experimenting with integration of C++ and Ruby. What exactly I would  
> like to do is to provide an option to use Ruby and wxRuby for creation of  
> GUI and doing algorithms in C++ and then displaying results in the openGL  
> Canvas.

I wasn’t totally clear what you wanted - do you want to end up with a  
ruby script that calls some C++ extensions, or a compiled C programme  
that calls wxRuby to do a GUI. I think the latter will be harder…

> But I would also like to transfer the data from the form built using Ruby  
> into some classes in C++. Like parameters: numbers and string. But I am  
> wondering if it is possible to create controls in Ruby and then just  
> assign then into C++ fields (the controls not values).  
> Not quite sure how this would work. Unless the interface of your C++  
> library is very complex, it might be easier to do it the other way  
> around, ie create a simple ruby wrapper around your C++ library (using  
> SWIG or RICE) then use Ruby to transfer the values into the C library.  
> Is there a particular reason this won’t work for you?  
> I thought these are in fact the same controls, they were written in C++,  
> but I guess txt is not of type [wxTextField \*], but rather  
> #SWIG::TYPE\_p\_wxTextCtrl:0xb7c49944  
> so how to get the pointer to wxTextField so I can manipulate the control  
> from cpp class like this
> 
> someText-\>GetValue()  
> SWIG provides a lot of useful functions for doing this, if you want. See  
> [SWIG and Ruby](http://www.swig.org/Doc1.3/Ruby.html#Ruby_nn50)

in particular, SWIG\_ConvertPtr which converts a VALUE to the underlying  
C++ object.

It’s generally used little directly, as it’s easier to use %extend to  
write methods in which the placeholder variable $self refers to the C++  
object.

alex
