XS Fun

Sawyer X ( @PerlSawyer)
XS is...
A glue layer between Perl and C/C++
Sections, macros, functions
Requires knowledge with C, Perl API, XS, typemaps...
XS is
misunderstood
No need to be an expert
Basic Perl API is simple
XS is not too difficult
Lots of options
All documente...
Except...
... except those that aren't documented
... except that the official tutorial sucks
... except that there's no b...
I guess I'll write one then!
XS Fun
A tutorial making XS fun
Starts easy, progresses slowly
Split to chapters, each taking a small task
A lot of explan...
Features
Already on Github
A few chapters already covered
Functions (XS, C)
Constructor
Simple methods
Missing
Complex methods
Converting objects with typemaps
Advanced XS
Quick glossary
SV = Scalar Value
Of:
IV = Integer Value (m $ = - 0
y i
3)
UV = Unsigned Integer Value (m $ = 3 0 . .
y u
0...
Examples
XSFun.pm
pcaeXFn
akg Su;
uesrc;
s tit
uewrig;
s anns
ueEpre;
s xotr
ueXLae;
s Sodr
uebs 'xotr;
s ae Epre'
or$ESO
u VRIN
='...
XSFun.xs
#nld "XENh
icue ETR."
#nld "elh
icue pr."
#nld "SBh
icue XU."
#nld "poth
icue ppr."
MDL =XFn
OUE
Su

PCAE=XFn
AKG...
XSFun.xs (more)
#nld <hoarn.>
icue crmpith
/ i tecd scin*
* n h oe eto /
cntca *
os hr
gtvrin)
e_eso(
CD:
OE
RTA =crmpitgt...
Audio::Chromaprint
Interface to Chromaprint library
Audio/Chromaprint.pm
pcaeAdo:hoarn;
akg ui:Crmpit
uesrc;
s tit
uewrig;
s anns
ueXLae;
s Sodr
or$ESO ='.0'
u VRIN
001;
XLae...
Chromaprint.xs
#nld "XENh
icue ETR."
#nld "elh
icue pr."
#nld "SBh
icue XU."
#nld "poth
icue ppr."
#nld <hoarn.>
icue crmp...
Chromaprint.xs
cntca *
os hr
vrinS *ef
eso(V sl)
CD:
OE
RTA =crmpitgtvrin)
EVL
hoarn_e_eso(;
OTU:RTA
UPT EVL
Constructor
#I Pr:
n el
sbnw{bes{,sit}
u e
ls } hf
#o..
r.
sbnw{
u e
m $ls =sit #o $[]
y cas
hf;
r _0
m %ah =(;
y hs
)
m $...
#Pr-el
uePr
sbnw{
u e
m $ls =sit #o $[]
y cas
hf;
r _0
m %ah =(;
y hs
)
m $ef =hs;
y sl
%ah
rtr bes$ef $ls;
eun ls sl, cas...
Conclusions
XS is not that complex
XS can be fun
You can do it!
Thank you
Homework:
github.com/xsawyerx/xs-fun
perldoc perlguts
perldoc perlapi
perldoc perlxs
XS Fun
Upcoming SlideShare
Loading in...5
×

XS Fun

672

Published on

A talk about XS Fun, an easy-going tutorial to Perl XS:
https://github.com/xsawyerx/xs-fun

This talk was originally given at Cluj.pm, on November 7th, 2013.

Published in: Technology, Sports
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
672
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "XS Fun"

  1. 1. XS Fun Sawyer X ( @PerlSawyer)
  2. 2. XS is... A glue layer between Perl and C/C++ Sections, macros, functions Requires knowledge with C, Perl API, XS, typemaps Written by our very best Complex, difficult, strenuous, laborious, painful, formidable (additional words can be found in thesaurus.com ) An impediment to Modern Perl
  3. 3. XS is misunderstood No need to be an expert Basic Perl API is simple XS is not too difficult Lots of options All documented
  4. 4. Except... ... except those that aren't documented ... except that the official tutorial sucks ... except that there's no better (or any other full) tutorial (at least not one I could find)
  5. 5. I guess I'll write one then!
  6. 6. XS Fun A tutorial making XS fun Starts easy, progresses slowly Split to chapters, each taking a small task A lot of explanations for beginners All examples work
  7. 7. Features Already on Github A few chapters already covered Functions (XS, C) Constructor Simple methods
  8. 8. Missing Complex methods Converting objects with typemaps Advanced XS
  9. 9. Quick glossary SV = Scalar Value Of: IV = Integer Value (m $ = - 0 y i 3) UV = Unsigned Integer Value (m $ = 3 0 . . y u 00.) NV = Double Value (m $ = 3 . 7 ) y d 071 PV = String Value (m $ = ' e l w r d ) y s hlo ol' SV = (another) Scalar Value AH = Array Value (m @ = q < e l w r d ) y a whlo ol> HV = Hash Value (m % = ( h l o = ' o l ' ) y h el > wrd ) RV = Reference Value (m $ a h e = h y hsrf %) That's it for now
  10. 10. Examples
  11. 11. XSFun.pm pcaeXFn akg Su; uesrc; s tit uewrig; s anns ueEpre; s xotr ueXLae; s Sodr uebs 'xotr; s ae Epre' or$ESO u VRIN ='.0' 001; or%XOTTG =('l'= [wgtvrin]) u EPR_AS al > q<e_eso> ; or@XOTO u EPR_K =(@ $XOTTG{al}}) { EPR_AS'l' ; XLae:la('Su' $ESO ) Sodr:od XFn, VRIN ; 1 ;
  12. 12. XSFun.xs #nld "XENh icue ETR." #nld "elh icue pr." #nld "SBh icue XU." #nld "poth icue ppr." MDL =XFn OUE Su PCAE=XFn AKG Su dul obe adnmesdul a dul b d_ubr(obe , obe ) CD: OE RTA =a+b EVL ; OTU: UPT RTA EVL S * V adnmespr(V*,S *) d_ubr_elS a V b CD: OE { cntdul sm=SN()+SN() os obe u vVa vVb; RTA =nwVvsm; EVL eSn(u) } OTU:RTA UPT EVL
  13. 13. XSFun.xs (more) #nld <hoarn.> icue crmpith / i tecd scin* * n h oe eto / cntca * os hr gtvrin) e_eso( CD: OE RTA =crmpitgtvrin) EVL hoarn_e_eso(; OTU:RTA UPT EVL #i vrint n eso.: ueXFn'al; s Su :l' i(gtvrin) '..' 'hoarn vrini 600 ) s e_eso(, 600, crmpit eso s ..' ; tvrint. o /eso. . k Altssscesu. l et ucsfl Fls1 Tss1 0wlcoksc (00 ur 00 ss+ 00 cs ie=, et=, allc es .3 s .1 y .2 ur 00 cy = 00 CU .0 ss .6 P) Rsl:PS eut AS
  14. 14. Audio::Chromaprint Interface to Chromaprint library
  15. 15. Audio/Chromaprint.pm pcaeAdo:hoarn; akg ui:Crmpit uesrc; s tit uewrig; s anns ueXLae; s Sodr or$ESO ='.0' u VRIN 001; XLae:la('ui:Crmpit,$ESO ) Sodr:od Ado:hoarn' VRIN ; 1 ;
  16. 16. Chromaprint.xs #nld "XENh icue ETR." #nld "elh icue pr." #nld "SBh icue XU." #nld "poth icue ppr." #nld <hoarn.> icue crmpith MDL =Ado:hoarn OUE ui:Crmpit PCAE=Ado:hoarn AKG ui:Crmpit
  17. 17. Chromaprint.xs cntca * os hr vrinS *ef eso(V sl) CD: OE RTA =crmpitgtvrin) EVL hoarn_e_eso(; OTU:RTA UPT EVL
  18. 18. Constructor #I Pr: n el sbnw{bes{,sit} u e ls } hf #o.. r. sbnw{ u e m $ls =sit #o $[] y cas hf; r _0 m %ah =(; y hs ) m $ef =hs; y sl %ah rtr bes$ef $ls; eun ls sl, cas }
  19. 19. #Pr-el uePr sbnw{ u e m $ls =sit #o $[] y cas hf; r _0 m %ah =(; y hs ) m $ef =hs; y sl %ah rtr bes$ef $ls; eun ls sl, cas } / i X * * n S / S * V nw cntca *ls ) e( os hr cas CD: OE / Cet ahs * * rae ah / H*hs =nwV) V ah eH(; / Cet arfrnet tehs * * rae eeec o h ah / S*cntsl =nwVnic (V*hs ) V os ef eR_on( S )ah ; / besit tepoe pcae* * ls no h rpr akg / RTA =s_ls(sl,g_tsp(cas 0)) EVL vbes ef vsahv ls, ; OTU:RTA UPT EVL
  20. 20. Conclusions XS is not that complex XS can be fun You can do it!
  21. 21. Thank you Homework: github.com/xsawyerx/xs-fun perldoc perlguts perldoc perlapi perldoc perlxs
  1. Gostou de algum slide específico?

    Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

×