GithubHelp home page GithubHelp logo

perlxs-rosetta's Introduction

Perl XS Rosetta Stone

The following is meant as a quick-and-dirty “cheat sheet” reference for XSUB authors. Many of the “translations” below can take multiple forms; the below is not a substitute for reading and digesting the relevant Perl documentation: perlxs, perlxstut, perlapi, perlguts, etc.

The following assumes knowledge of C, including use of pointers.

Scalars: assignment

Perl XS
my $v SV *mysv = newSV(0)
$v = undef sv_set_undef(mysv)
my $v = 1 SV *mysv = newSVuv(1)
$v = 1 sv_setuv(mysv, 1)
$v = -1 sv_setiv(mysv, -1)
$v = 'literal' sv_setpvs(mysv, "literal")
$v = $other_str sv_setpvn(mysv, otherstr, length_of_otherstr)

Scalars: concatenation

Perl XS
$v .= 'literal' sv_catpvs(mysv, "literal")
$v .= $other_str sv_catpvn(mysv, otherstr, length_of_otherstr)

Scalars: length

Perl XS
length $a sv_len_utf8(mysv)

Arrays

Perl XS
my @a AV *myav = newAV()
@a = () av_clear(myav)
push @a, $foo av_push(myav, foo)
$foo = pop @a SV *foo = av_pop(myav)
$foo = shift @a SV *foo = av_shift(myav)
($old) = splice(@a, 2, 1, $foo) SV **old = av_store(myav, 2, foo)
my ($el) = splice(@, 2, 1) SV *myel = av_delete(myav, 2, 0)
() = splice(@, 2, 1) av_delete(myav, 2, G_DISCARD)
@INC get_av("main::INC") or (GvAV(PL_incgv))

Packages/Namespaces

Perl XS
__PACKAGE__ HvNAME( (HV*)CopSTASH(PL_curcop) )

Global State

Perl XS
${^GLOBAL_PHASE} PL_phase / PL_dirty

perlxs-rosetta's People

Contributors

fgasper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

saintserge

perlxs-rosetta's Issues

Incorporate magic

Per IRC: lot of perlapi functions do not evaluate magic on every parameter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.