unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Guile and C++
@ 2010-05-13 19:53 Noah Lavine
  2010-05-14 19:54 ` objc
  0 siblings, 1 reply; 5+ messages in thread
From: Noah Lavine @ 2010-05-13 19:53 UTC (permalink / raw)
  To: guile-user

Dear Guile-users,

I am wondering what the best way is to connect Guile with C++ code. I
notice that several large programs use Guile in this way (TeXmacs and
LilyPond), so it seems that it is possible to do it, and it works well
enough that you can write a large, functioning program with it.
However, I don't see any mention of it in the Guile documentation.
Does Guile come with the ability to use C++ code, or should I plan on
writing C wrappers for any functions I want to use? (I'm planning on
using Guile 2.0, if that makes a difference.)

Thank you
Noah Lavine



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Guile and C++
  2010-05-13 19:53 Guile and C++ Noah Lavine
@ 2010-05-14 19:54 ` objc
  2010-05-14 20:05   ` Noah Lavine
  0 siblings, 1 reply; 5+ messages in thread
From: objc @ 2010-05-14 19:54 UTC (permalink / raw)
  To: Noah Lavine, guile-user

Dear Noah,

there are no inherent problems with mixing Guile, C, C++, guile ........(MS 
windows, LINUX,GNUStep,X11)
Depends on how you order your includes, which OS you use, version conflicts 
etc.
Using scoping rules to the fullest you can pretty much mix it up as you 
like.

obj.

--------------------------------------------------
From: "Noah Lavine" <noah549@gmail.com>
Sent: Thursday, May 13, 2010 8:53 PM
To: <guile-user@gnu.org>
Subject: Guile and C++

> Dear Guile-users,
>
> I am wondering what the best way is to connect Guile with C++ code. I
> notice that several large programs use Guile in this way (TeXmacs and
> LilyPond), so it seems that it is possible to do it, and it works well
> enough that you can write a large, functioning program with it.
> However, I don't see any mention of it in the Guile documentation.
> Does Guile come with the ability to use C++ code, or should I plan on
> writing C wrappers for any functions I want to use? (I'm planning on
> using Guile 2.0, if that makes a difference.)
>
> Thank you
> Noah Lavine
>
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Guile and C++
  2010-05-14 19:54 ` objc
@ 2010-05-14 20:05   ` Noah Lavine
  2010-05-14 21:06     ` Hans Aberg
  0 siblings, 1 reply; 5+ messages in thread
From: Noah Lavine @ 2010-05-14 20:05 UTC (permalink / raw)
  To: objc; +Cc: guile-user

Thanks a lot.

How would this work if I wanted to not run Guile embedded in a C++
program, but instead load the C++ code at runtime from a regular Guile
interpreter? (This could use either the libffi binding or the regular
Guile ones.)

Thank you
Noah

On Fri, May 14, 2010 at 3:54 PM, objc <objcjohn@hotmail.com> wrote:
> Dear Noah,
>
> there are no inherent problems with mixing Guile, C, C++, guile ........(MS
> windows, LINUX,GNUStep,X11)
> Depends on how you order your includes, which OS you use, version conflicts
> etc.
> Using scoping rules to the fullest you can pretty much mix it up as you
> like.
>
> obj.
>
> --------------------------------------------------
> From: "Noah Lavine" <noah549@gmail.com>
> Sent: Thursday, May 13, 2010 8:53 PM
> To: <guile-user@gnu.org>
> Subject: Guile and C++
>
>> Dear Guile-users,
>>
>> I am wondering what the best way is to connect Guile with C++ code. I
>> notice that several large programs use Guile in this way (TeXmacs and
>> LilyPond), so it seems that it is possible to do it, and it works well
>> enough that you can write a large, functioning program with it.
>> However, I don't see any mention of it in the Guile documentation.
>> Does Guile come with the ability to use C++ code, or should I plan on
>> writing C wrappers for any functions I want to use? (I'm planning on
>> using Guile 2.0, if that makes a difference.)
>>
>> Thank you
>> Noah Lavine
>>
>>
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Guile and C++
  2010-05-14 20:05   ` Noah Lavine
@ 2010-05-14 21:06     ` Hans Aberg
  2010-05-18 21:22       ` David Fang
  0 siblings, 1 reply; 5+ messages in thread
From: Hans Aberg @ 2010-05-14 21:06 UTC (permalink / raw)
  To: Noah Lavine; +Cc: guile-user

On 14 May 2010, at 22:05, Noah Lavine wrote:

> How would this work if I wanted to not run Guile embedded in a C++
> program, but instead load the C++ code at runtime from a regular Guile
> interpreter? (This could use either the libffi binding or the regular
> Guile ones.)

Since Guile is written in C, formally according to the C++ standard,  
you can only load Guile from C++ code, and not the opposite. So main()  
must be C++.

GCC though has integrated C and C++ fully, it seems. So you can call C+ 
+ from C code, but the latter do not implement C++ exception stacks,  
and may not call C++ initialization function properly (I haven't  
checked). It means that throwing and catching exceptions within C++  
functions called from C seems to work fine, but if one tries to pass  
it through a C function, the program will throw a terminate exception.

   Hans





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Guile and C++
  2010-05-14 21:06     ` Hans Aberg
@ 2010-05-18 21:22       ` David Fang
  0 siblings, 0 replies; 5+ messages in thread
From: David Fang @ 2010-05-18 21:22 UTC (permalink / raw)
  To: Hans Aberg; +Cc: guile-user, Noah Lavine

>> How would this work if I wanted to not run Guile embedded in a C++
>> program, but instead load the C++ code at runtime from a regular Guile
>> interpreter? (This could use either the libffi binding or the regular
>> Guile ones.)
>
> Since Guile is written in C, formally according to the C++ standard, you can 
> only load Guile from C++ code, and not the opposite. So main() must be C++.
>
> GCC though has integrated C and C++ fully, it seems. So you can call C++ from 
> C code, but the latter do not implement C++ exception stacks, and may not 
> call C++ initialization function properly (I haven't checked). It means that 
> throwing and catching exceptions within C++ functions called from C seems to 
> work fine, but if one tries to pass it through a C function, the program will 
> throw a terminate exception.

Hi,
 	FWIW, I've used guile with C++ both ways: calling the main REPL 
loop in libguile from a C++ main, and also by creating loadable modules in 
C++, and calling load-extension with an initialization function.  Both 
work just fine, but you should be aware that guile errors do not unwind 
the stack on error, so C++ stack objects do not get destroyed in the event 
of exceptions/errors in the guile library.  I usually write the 
initialization function in the extern "C" namespace to avoid symbol name 
mangilng.
 	Also, global statics in C++ modules are initialized upon 
loading, from what I've seen.

Fang


David Fang
http://www.csl.cornell.edu/~fang/
http://www.achronix.com/




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-05-18 21:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-13 19:53 Guile and C++ Noah Lavine
2010-05-14 19:54 ` objc
2010-05-14 20:05   ` Noah Lavine
2010-05-14 21:06     ` Hans Aberg
2010-05-18 21:22       ` David Fang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).