Skip to content

hgtw/perlbind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Perlbind Library

linux windows

This is a C++14 binding library for perl. It can be used as an alternative to writing XS for embedding perl in C++ projects.

Basic Usage

#include <perlbind/perlbind.h>

int get_sum(int a, int b)
{
  return a + b;
}

int main()
{
  perlbind::interpreter state;

  auto package = state.new_package("mypackage");
  package.add("get_sum", &get_sum);

  try
  {
    state.load_script("main", "script.pl");
    int result = state.call_sub<int>("main::testsub");
    printf("result: %d\n", result); // result: 15
  }
  catch (std::exception& e)
  {
    printf("error: %s\n", e.what());
  }

  return 0;
}
# script.pl
sub testsub {
  my $sum = mypackage::get_sum(5, 10);
  return $sum;
}

About

A C++ binding library for perl

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published