Wow.  This is awesome!  Thank you so much for taking the time to reply to my
request with so much detailed information.
I'm going to sit down and update my examples, and then go back and update my
page on perlmonks so this information will be available for anyone else who
runs into these issues.

Thank you so much for your help!

-Ryan Dietrich

On Sat, Aug 7, 2010 at 5:53 AM, Mattia Barbon <mattia.bar...@libero.it>wrote:

> Ryan Dietrich wrote:
>
>  Hi,
>
>
>  Greetings, I've been studying how to interface C++ and Perl using XS.
>> I was aware of this project, and saw that it is doing things that are
>> currently beyond my skillset.
>>
>> I was hoping I could get a few answers.
>>
>> 1. What is the general approach of handling exceptions?
>>
>
>  At the moment there is partial support for handling exceptions in XS++: by
> default all exceptions are caught, and the XS wrapper die()s with a message.
>  If the exception is derived from std::exception, the message includes the
> text of the what() method, otherwise a generic error message is thrown.
>  Support for propagating the complete exception object to Perl is planned
> but not implemented yet.
>
>  If for any reason you don't want to use XS++, you need to put a try/catch
> block around the XS code and handle the exceptions manually
>
> int
> foo(int bar)
>  CODE:
>    try [
>      RETVAL = foo(bar);
>    } catch (...) {
>      ...
>    }
>  OUTPUT: RETVAL
>
>
>  2. How do you map multiple custom C++ objects out of a single header file
>> using XS?
>>
>
>  There are two approaches:
>
> 1 - you can split the XS code in multiple XS files and then include them
> all in a single top-level file, using the INCLUDE: directive; in this case
> you do not need to do anything special
> 2 - if you do it the way Wx does, you need to list all the object files for
> XS top-level modules in the OBJECTS MakeMaker parameter; every top-level XS
> file must have a different MODULE directive; one of the XS files must have a
> MODULE directive matching the .pm module name, and in this module you need
> to add this code:
>
> // in the C section
> extern "C" {
>    XS( boot_SubModule1 );
>    XS( boot_Another_Sub_Module );
>    ...
> }
>
> // in the XS section:
> BOOT:
>  newXSproto( "My::_boot_SubModule1", boot_SubModule1, file, "$$" );
>  ...
>
> // in the My.pm file
> _boot_SubModule1( 'My', $XS_VERSION );
>
>  Note that Wx uses a hybrid approach (multiple top-level XS files that each
> include multiple XS files from the XS subdirectory).
>
>
>  For reference, here's my post on Perlmonks (it's a little wordy).
>>
>> http://perlmonks.org/?node_id=853194
>>
>
> HTH,
> Mattia
>
>

Reply via email to