[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to interface with an API written in C++?

Derek Haskin

5/5/2005 2:14:00 AM





Hi,

Does any know how I would go about making calls to a set of APIs written in
C++

The reason is I want to use ruby to make direct calls to our source control
tool which is Harvest.

thanks
derek.



<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Privileged/Confidential information may be contained in this message.
If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone.
In such a case, you should destroy this message and kindly notify the sender by reply e-mail or by telephone on (03) 9612-6999 or (61) 3 9612-6999.
Please advise immediately if you or your employer does not consent to Internet e-mail for messages of this kind.
Opinions, conclusions and other information in this message that do not relate to the official business of Transurban Limited and CityLink Melbourne Limited shall be understood as neither given nor endorsed by them.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>



57 Answers

Piers Harding

5/5/2005 8:25:00 AM

0


Hi - my only experience with this is with Perl, but I would take a guess
that the process should be similar (someone else my know better).

Basically you would create a normal C extension for Ruby, but ensure
that your symbols are externalised (extern "C" { ... }), and then use
the c++ compiler. Then create your subroutines as normal, and call out
to the C++ library functions (thatyou need to link in).
I've not tried it myself, but I would have thought that it could be made
to fly?

Cheers,

Piers Harding.


On Thu, May 05, 2005 at 11:14:07AM +0900, Derek Haskin wrote:
>
>
>
>
> Hi,
>
> Does any know how I would go about making calls to a set of APIs written in
> C++
>
> The reason is I want to use ruby to make direct calls to our source control
> tool which is Harvest.
>
> thanks
> derek.
>
>
>
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> Privileged/Confidential information may be contained in this message.
> If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone.
> In such a case, you should destroy this message and kindly notify the sender by reply e-mail or by telephone on (03) 9612-6999 or (61) 3 9612-6999.
> Please advise immediately if you or your employer does not consent to Internet e-mail for messages of this kind.
> Opinions, conclusions and other information in this message that do not relate to the official business of Transurban Limited and CityLink Melbourne Limited shall be understood as neither given nor endorsed by them.
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>

--
http://www.piersh...
http://search.cpan.o...

Nikolai Weibull

5/5/2005 9:49:00 AM

0

Derek Haskin, May 5:

> Does any know how I would go about making calls to a set of APIs
> written in C++

You could search the archives at http://ruby... before asking
these questions. Anyway, here are two links with information,
http://aeditor.rubyforge.org/ruby_cplusplus/... and
http://www.ruby-doc.org/docs/Progra.... The first is C++
specific, the second contains information relating to API interfacing in
general.

[cut disclaimer]

Do you really, and I mean really, need to include that disclaimer?,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


Piers Harding

5/5/2005 12:23:00 PM

0


OK - but here is a way to roll your own:
take one C++ file called dohello.cpp:
extern "C" {
void Init_dohello(void);
}
#include <ruby.h>
#include <iostream>

using namespace std;

int cpp_hello()
{
cout << "Hello World!" << endl;
return 0;
}

static VALUE my_hello( ) {
cpp_hello();
return Qtrue;
}

void
Init_dohello(void) {
VALUE hello;
hello = rb_define_module("CPPHello");
rb_define_module_function(hello, "do_hello", ( VALUE (*)(...) ) my_hello, 0);
}


Take an extconf.rb file:
require 'mkmf'
have_library("stdc++")
create_makefile("dohello")


And a test.rb file:
require "dohello.so"
CPPHello.do_hello()

And stir to your liking :-)

P.S. this was done under Linux FC3 + Ruby 1.8.2


Cheers,

Piers Harding.







On Thu, May 05, 2005 at 06:49:04PM +0900, Nikolai Weibull wrote:
> Derek Haskin, May 5:
>
> > Does any know how I would go about making calls to a set of APIs
> > written in C++
>
> You could search the archives at http://ruby... before asking
> these questions. Anyway, here are two links with information,
> http://aeditor.rubyforge.org/ruby_cplusplus/... and
> http://www.ruby-doc.org/docs/Progra.... The first is C++
> specific, the second contains information relating to API interfacing in
> general.
>
> [cut disclaimer]
>
> Do you really, and I mean really, need to include that disclaimer?,
> nikolai
>
> --
> Nikolai Weibull: now available free of charge at http:/...!
> Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
> main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

--
http://www.piersh...
http://raa.ruby-lang.org/search.rhtml?search=piers&search_ta...
http://search.cpan.o...

Nikolai Weibull

5/5/2005 12:44:00 PM

0

Piers Harding, May 5:

> OK - but here is a way to roll your own:
â?®

I don't understand what this has to do with what I said,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


Piers Harding

5/5/2005 1:07:00 PM

0

It continues the conversation.

You came up with one set of suggestions based around rubyembed, and
Swing. I just demonstrated that you can do it without that if you
prefer not to go down that path.

Cheers,

Piers Harding.


On Thu, May 05, 2005 at 09:43:44PM +0900, Nikolai Weibull wrote:
> Piers Harding, May 5:
>
> > OK - but here is a way to roll your own:
> ?
>
> I don't understand what this has to do with what I said,
> nikolai
>
> --
> Nikolai Weibull: now available free of charge at http:/...!
> Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
> main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

--
http://www.piersh...
http://raa.ruby-lang.org/search.rhtml?search=piers&search_ta...
http://search.cpan.o...

Nikolai Weibull

5/5/2005 2:32:00 PM

0

Piers Harding, May 5:

> It continues the conversation.

Ah, not very obvious when you push down what I was saying to the bottom
of your message. Perhaps cut out only the vital parts of my message,
paste them at the top, and then write your reply?

> You came up with one set of suggestions based around rubyembed, and
> Swing. I just demonstrated that you can do it without that if you
> prefer not to go down that path.

I assume you mean SWIG. Sure, that's a valid point; I've never really
liked SWIG myself,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


Gennady

5/5/2005 3:40:00 PM

0

For a long time I've been doing C++/Ruby interfacing mannually. And
about 2 weeks ago I got to giving SWIG a try (version 1.3.24).

I was truelly amazed with what I got. It transforms your C++ classes
into Ruby classes practically seamlessly, even giving you opportunity to
adjust to naming conventions simply by edditing a SWIG interface file.
Included typemaps allow you, for example, return std::string from your
C++ method, and automatically gets converted and returned to the Ruby
world as Ruby string, without you doing a stir. Isn't it amazing? ;-)

However, you can still use ruby C API in your C++ methods if you need
it. In particular, I use it to implement iterator-like methods using
rb_is_block_given_p() and rb_yield and SWIG's SWIG_NewPointerObj(...)
function.

After throwing away tons of now unnecessary code, I am fully convinced
that SWIG is the way to go for C++/Ruby integration.

Gennady.

Nikolai Weibull wrote:
> Piers Harding, May 5:
>
>
>>It continues the conversation.
>
>
> Ah, not very obvious when you push down what I was saying to the bottom
> of your message. Perhaps cut out only the vital parts of my message,
> paste them at the top, and then write your reply?
>
>
>>You came up with one set of suggestions based around rubyembed, and
>>Swing. I just demonstrated that you can do it without that if you
>>prefer not to go down that path.
>
>
> I assume you mean SWIG. Sure, that's a valid point; I've never really
> liked SWIG myself,
> nikolai
>



Nikolai Weibull

5/5/2005 7:26:00 PM

0

Edgardo Hames, May 6:

> Nikolai Weibull wrote:

> > [cut disclaimer]

> > Do you really, and I mean really, need to include that disclaimer?

> Sometimes, those disclaimers are automatically added by the company
> MTA and you have no way to avoid it.

Thatâ??s what the â??and I mean reallyâ? nonessential clause was for,
nikolai

--
Nikolai Weibull: now available free of charge at http:/...!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


Ramon F Herrera

6/12/2012 12:37:00 PM

0

On Jun 12, 7:06 am, Sancho Panza <otterpo...@xhotmail.com> wrote:
> On 6/12/2012 12:10 AM, richard wrote:
>
>
>
>
>
>
>
>
>
> > On Mon, 11 Jun 2012 19:50:38 -0700 (PDT), Criminal Drivers Murder 35,000
> > Americans a Year wrote:
>
> >> This is what happens when you have a super-racist white hater as
> >> president.  Whites have no rights in america even though we built this
> >> country.
>
> >>http://losangeles.cbslocal.com/2012/06/11/white-student-ret......
>
> >> White Student Returns $1,000 Scholarship Intended For Black Students
>
> >> June 11, 2012 11:31 AM
>
> >> RIVERSIDE (CBS) — A 17-year-old student at King High School in
> >> Riverside has returned a $1,000 scholarship intended for black
> >> students because he is white.
>
> >> Jeffrey Warren and his father Rod returned the scholarship from the
> >> Martin Luther King Senior Citizens Club the night the teen was
> >> announced as the winner of the African-American student scholarship,
> >> according to the Riverside Press-Enterprise.
>
> >> Jeffrey, who has a 4.25 cumulative grade-point average, applied for 27
> >> scholarships and won three others in addition to the award from the
> >> Martin Luther King Senior Citizens Club, which only specified that
> >> African Americans were “encouraged to apply,” the newspaper reported.
> >> School counselors were informed that the scholarship was for black
> >> students.
>
> >> The club intends to change the language on next year’s application to
> >> clarify who is eligible, according to the Press-Enterprise.
>
> >> The returned scholarship was later awarded to an African-American girl
> >> at King High School.
>

> That could create an interesting constitutional question
> about equal treatment under the law.

No, it cannot.

-RFH

SaPeIsMa

6/12/2012 1:06:00 PM

0


"Sancho Panza" <otterpower@xhotmail.com> wrote in message
news:4fd730ae$0$6057$607ed4bc@cv.net...
> On 6/12/2012 12:10 AM, richard wrote:
>> On Mon, 11 Jun 2012 19:50:38 -0700 (PDT), Criminal Drivers Murder 35,000
>> Americans a Year wrote:
>>
>>> This is what happens when you have a super-racist white hater as
>>> president. Whites have no rights in america even though we built this
>>> country.
>>>
>>> http://losangeles.cbslocal.com/2012/06/11/white-student-returns-1000-scholarship-intended-for-black...
>>>
>>> White Student Returns $1,000 Scholarship Intended For Black Students
>>>
>>> June 11, 2012 11:31 AM
>>>
>>> RIVERSIDE (CBS) ? A 17-year-old student at King High School in
>>> Riverside has returned a $1,000 scholarship intended for black
>>> students because he is white.
>>>
>>> Jeffrey Warren and his father Rod returned the scholarship from the
>>> Martin Luther King Senior Citizens Club the night the teen was
>>> announced as the winner of the African-American student scholarship,
>>> according to the Riverside Press-Enterprise.
>>>
>>> Jeffrey, who has a 4.25 cumulative grade-point average, applied for 27
>>> scholarships and won three others in addition to the award from the
>>> Martin Luther King Senior Citizens Club, which only specified that
>>> African Americans were ?encouraged to apply,? the newspaper reported.
>>> School counselors were informed that the scholarship was for black
>>> students.
>>>
>>> The club intends to change the language on next year?s application to
>>> clarify who is eligible, according to the Press-Enterprise.
>>>
>>> The returned scholarship was later awarded to an African-American girl
>>> at King High School.
>
> That could create an interesting constitutional question about equal
> treatment under the law.
>

NO it won't
It's a private group
And they can give their money to whomever they choose.