wxRuby / wxWigets with C++

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.

£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
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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs