in reply to Procedural and object oriented interface in Perl/XS
Inline::C is just XS under the hood, and the XS file that it autogenerates and compiles (and can be found under ./_Inline/build) is:use strict; use warnings; use Inline C => Config => CLEAN_AFTER_BUILD => 0, BUILD_NOISY => 1; use Inline C => <<'EOC'; double wrap_cos(SV * in) { if(sv_isobject(in)) { HV *self_hv = MUTABLE_HV(SvRV(in)); SV **callback_ptr = hv_fetchs(self_hv, "Number", 0); return cos(SvNV(*callback_ptr)); } return cos(SvNV(in)); } EOC my $angle = 0.5; my $x = {'Number' => $angle}; bless $x; print wrap_cos($x), "\n"; # Output: 0.877582561890373 print wrap_cos($angle), "\n"; # Output: 0.877582561890373
Maybe there's something there that helps you ... or maybe not ;-)#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "INLINE.h" double wrap_cos(SV * in) { if(sv_isobject(in)) { HV *self_hv = MUTABLE_HV(SvRV(in)); SV **callback_ptr = hv_fetchs(self_hv, "Number", 0); return cos(SvNV(*callback_ptr)); } return cos(SvNV(in)); } MODULE = try_pl_96f2 PACKAGE = main PROTOTYPES: DISABLE double wrap_cos (in) SV * in
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Procedural and object oriented interface in Perl/XS
by stewa02 (Novice) on Oct 24, 2014 at 05:49 UTC |