An alternative to xs

  • 348 views
Uploaded on

XS has been the way to extend perl with C or C++ code for the past decade and a half. It has become a powerful but hard to tame beast. …

XS has been the way to extend perl with C or C++ code for the past decade and a half. It has become a powerful but hard to tame beast.

In this lightning talk, I'm exploring an entirely new approach to extending perl, based on C++ metaprogramming instead of preprocessing. One that doesn't require a programmer familiar with both to learn yet another language.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
348
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
1
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. An alternative to XS‎ Leon Timmermans
  • 2. XS
      • Preprocessor
        • XS to C
        • C to Binary
      • Pros
        • Flexible
        • Mature
      • Cons
        • Yet another languages to learn
        • … that isn't even a language
        • Requires some understanding of the interpreter
        • Limited C++ support
  • 3. Templates
    • A compile-time feature of C++
    • Turns meta code into code
    • Turing complete, purely functional
  • 4. Example
    • #! /usr/bin/perl
    • use Modern::Perl;
    • use Extend qw/hello/;
    • hello('world');
  • 5. Example
    • package Extend;
    • use Modern::Perl
    • use Exporter 5.57 qw/import/;
    • our @EXPORT_OK = qw/hello/;
    • use Perlpp::Extend;
    • 1;
  • 6. Example
    • #include <perl++/perl++.h>
    • #include <perl++/extend.h>
    • using namespace perl;
    • static void hello(const char* world) {
    • printf(&quot;Hello %s &quot;, world);
    • }
    • static void exporter(Package& extend) {
    • extend.add(&quot;hello&quot;, hello);
    • }
    • EXPORTER(exporter);
  • 7. Example 2
    • #include <perl++/perl++.h>
    • #include <perl++/extend.h>
    • using namespace perl;
    • struct foo {
    • foo(const std::string&);
    • void bar(int barista);
    • std::string buz;
    • };
    • static void exporter(Class<foo>& extend) {
    • extend.add(init<std::string>());
    • extend.add(&quot;bar&quot;, &foo::bar);
    • extend.add(&quot;buz&quot;, &foo::buz);
    • }
    • EXPORTER(exporter);
  • 8. Thank you
    • Code at http://github.com/Leont/libperl--
      • CPAN will follow soon
    • Thanks for listening
    • Thanks EPO for sending me here
      • I'm the send-a-newbe