Skip to content

Instantly share code, notes, and snippets.

@Leont
Created March 22, 2010 15:00
Show Gist options
  • Save Leont/340155 to your computer and use it in GitHub Desktop.
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++
/* 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);
#! /usr/bin/perl
use Modern::Perl;
use Extend qw/hello/;
hello('world');
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