Created
March 22, 2010 15:00
-
-
Save Leont/340155 to your computer and use it in GitHub Desktop.
A simple example of how you can export your C++ library to perl using libperl++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Beat that, XS! Exporting functions and methods from C++ to Perl with just one macro */ | |
#include <perl++/perl++.h> | |
#include <perl++/extend.h> | |
using namespace perl; | |
static void hello(const char* world) { | |
printf("Hello %s\n", world); | |
} | |
static void exporter(Package& extend) { | |
extend.add("hello", hello); | |
} | |
EXPORTER(exporter); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use Modern::Perl; | |
use Extend qw/hello/; | |
hello('world'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Extend; | |
use Modern::Perl | |
use Exporter 5.57 qw/import/; | |
our @EXPORT_OK = qw/hello/; | |
use Perlpp::Extend; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment