Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
•   #import <Foundation/Foundation.h>    int main(int argc, char** argv) {        NSAutoreleasePool* pool =             [[...
•   #include   "EXTERN.h"    #include   "perl.h"    #include   "XSUB.h"    #include   "ppport.h"    XS(func) {        dXSA...
• package Foo;  use strict;  use XSLoader;  XSLoader::load __PACKAGE__, $VERSION;  1;
• use   Foo;  Foo::xs_function();
•   use inc::Module::Install;    # some basic descriptions here    use_ppport 3.19;    WriteAll;
•   #include   "EXTERN.h"    #include   "perl.h"    #include   "XSUB.h"    #include   "ppport.h"    // undefine Move macro...
• #include "EXTERN.h"  #include "perl.h"  #include "XSUB.h"  #include "ppport.h"
• #undef   Move
• XS(function)   {      dXSARGS;      // code here      XSRETURN(0);  }
• XS(function)   {      dXSARGS;      // code here      ST(0) = some_sv;      XSRETURN(1);  }
• XS(function)   {      dXSARGS;      // code here      ST(0) = some_sv;      ST(1) = some_sv2;      XSRETURN(2);  }
•   XS(function) {        dXSARGS;        SV* sv_args1 = ST(0);        SV* sv_args2 = ST(1);        // code here        ST...
•   XS(function) {        dXSARGS;        if (items < 2) {            Perl_croak(aTHX_ "Usage: function($args1, $args2)");...
STRLEN len;char* c = SvPV(sv, len);NSString* str = [NSString stringWithUTF8String:c];SV* sv = sv_2mortal(newSV(0));sv_setp...
NSNumber* n;if (SvNOKp(sv)) {    n = [NSNumber numberWithDouble:(double)SvNVX(sv))];}else if (SvIOK_UV(sv)) {    n = [NSNu...
• use   Cocoa::Growl :all;  my $installed = growl_installed();  my $running   = growl_running();
• use   Cocoa::Growl :all;  # register application  growl_register(      app            => My growl script,      icon     ...
• use   Cocoa::Growl :all;  # show growl notification  growl_notify(      name        => Notification1,      title       =...
•   use Cocoa::EventLoop;    use Cocoa::Growl :all;    growl_register(        name          => test script,        notific...
use AnyEvent;use Cocoa::EventLoop;# then all anyevent based api useCocoa::EventLoop!
•   use AnyEvent;    use Cocoa::EventLoop;    use Cocoa::Growl;    my $cv = AE::cv;    growl_notify(        name         =...
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Upcoming SlideShare
Loading in …5
×

Hacking Mac OSX Cocoa API from Perl

5,359 views

Published on

Published in: Technology
  • Be the first to comment

Hacking Mac OSX Cocoa API from Perl

  1. 1. • #import <Foundation/Foundation.h> int main(int argc, char** argv) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; // Objective-C code here NSLog(@”Hello World!”); [pool drain]; return 0; }
  2. 2. • #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" XS(func) { dXSARGS; // code here XSRETURN(0); } XS(boot_Foo) { newXS("Foo::xs_function", func, __FILE__); }
  3. 3. • package Foo; use strict; use XSLoader; XSLoader::load __PACKAGE__, $VERSION; 1;
  4. 4. • use Foo; Foo::xs_function();
  5. 5. • use inc::Module::Install; # some basic descriptions here use_ppport 3.19; WriteAll;
  6. 6. • #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" // undefine Move macro, this is conflict to Mac OS X QuickDraw API. #undef Move #import <Foundation/Foundation.h> XS(hello) { dXSARGS; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello!"); [pool drain]; XSRETURN(0); } XS(boot_Hello) { newXS("Hello::hello", hello, __FILE__); }
  7. 7. • #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h"
  8. 8. • #undef Move
  9. 9. • XS(function) { dXSARGS; // code here XSRETURN(0); }
  10. 10. • XS(function) { dXSARGS; // code here ST(0) = some_sv; XSRETURN(1); }
  11. 11. • XS(function) { dXSARGS; // code here ST(0) = some_sv; ST(1) = some_sv2; XSRETURN(2); }
  12. 12. • XS(function) { dXSARGS; SV* sv_args1 = ST(0); SV* sv_args2 = ST(1); // code here ST(0) = some_sv; ST(1) = some_sv2; XSRETURN(2); }
  13. 13. • XS(function) { dXSARGS; if (items < 2) { Perl_croak(aTHX_ "Usage: function($args1, $args2)"); } SV* sv_args1 = ST(0); SV* sv_args2 = ST(1); // code here ST(0) = some_sv; ST(1) = some_sv2; XSRETURN(2); }
  14. 14. STRLEN len;char* c = SvPV(sv, len);NSString* str = [NSString stringWithUTF8String:c];SV* sv = sv_2mortal(newSV(0));sv_setpv(sv, [str UTF8String]);
  15. 15. NSNumber* n;if (SvNOKp(sv)) { n = [NSNumber numberWithDouble:(double)SvNVX(sv))];}else if (SvIOK_UV(sv)) { n = [NSNumber numberWithDouble:(double)SvUV(sv))];}else if (SvIOKp(sv)) { n = [NSNumber numberWithDouble:(double)SvIV(sv))];}SV* sv = sv_2mortal(newSVnv([n doubleValue]));
  16. 16. • use Cocoa::Growl :all; my $installed = growl_installed(); my $running = growl_running();
  17. 17. • use Cocoa::Growl :all; # register application growl_register( app => My growl script, icon => /path/to/icon.png, # or http://urlto/icon notifications => [qw(Notification1 Notification2)], );
  18. 18. • use Cocoa::Growl :all; # show growl notification growl_notify( name => Notification1, title => Hello!, description => Growl world!, );
  19. 19. • use Cocoa::EventLoop; use Cocoa::Growl :all; growl_register( name => test script, notifications => [test notification], ); my $wait = 1; growl_notify( name => test notification, title => Hello, description => Growl World!, on_click => sub { warn click; $wait = 0; }, on_timeout => sub { warn timeout; $want = 0; }, ); Cocoa::EventLoop->run_while(0.1) while unless $wait;
  20. 20. use AnyEvent;use Cocoa::EventLoop;# then all anyevent based api useCocoa::EventLoop!
  21. 21. • use AnyEvent; use Cocoa::EventLoop; use Cocoa::Growl; my $cv = AE::cv; growl_notify( name => test notification, title => Hello, description => Growl World!, on_click => sub { warn ‘click’; $cv->send; }, on_timeout => sub { warn ‘timeout’; $cv->send; }, ); $cv->recv;

×