#!/usr/bin/perl
use Inline C;
use strict;
use warnings;
print mkstr() . "\n";
__END__
__C__
SV* mkstr() {
return newSVpv("This is another string!", 0);
}
####
#!/usr/bin/perl
use Inline C;
use strict;
use warnings;
use Data::Dumper;
my $arr = mkarr();
print ref($arr) . "\n";
print Dumper($arr) . "\n";
__END__
__C__
AV* mkarr() {
int i;
int size = 10;
SV** pint = (SV **) malloc(size * sizeof(SV*));
for(i = 0; i < size; ++i)
pint[i] = newSViv(i);
return av_make(size, pint);
}
####
#!/usr/bin/perl
use Inline C;
use strict;
use warnings;
use Data::Dumper;
my $hash = mkhash();
print ref($hash) . "\n";
print Dumper($hash) . "\n";
__END__
__C__
HV* mkhash() {
HV *hash = newHV();
hv_store(hash, "name", 5, newSVpv("John Doe", 0), 0);
hv_store(hash, "age", 4, newSViv(42), 0);
return hash;
}
####
#!/usr/bin/perl
use Inline C;
use strict;
use warnings;
use Data::Dumper;
my $obj = mkobj();
print ref($obj) . "\n";
print Dumper($obj) . "\n";
__END__
__C__
SV* mkobj() {
HV* hash = newHV();
hv_store(hash, "name", 5, newSVpv("John Doe", 0), 0);
hv_store(hash, "age", 4, newSViv(42), 0);
SV* rv = newRV_inc((SV*) hash);
return sv_bless(rv, gv_stashpv("MyClass", GV_ADD));
}