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
In reply to Re: Procedural and object oriented interface in Perl/XS
by syphilis
in thread Procedural and object oriented interface in Perl/XS
by stewa02
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |