C-inline-function-call.pl 767 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/perl
  2. #
  3. ## This file is a concept.
  4. #
  5. # In one day, maybe, Sidef will use 'Inline C' in Sidef::Exec
  6. # to make things a little bit faster... :)
  7. use 5.010;
  8. use strict;
  9. use warnings;
  10. use Inline 'C';
  11. package Test {
  12. sub new {
  13. my (undef, %opt) = @_;
  14. bless \%opt, __PACKAGE__;
  15. }
  16. sub add_value {
  17. my ($self) = @_;
  18. say "@_ ($#_)";
  19. say $self->{one} + $self->{two};
  20. }
  21. }
  22. my $obj = Test->new(one => 12, two => 3);
  23. my $method = 'add_value';
  24. my $func = ref($obj) . '::' . $method;
  25. c_call($obj, $func);
  26. __DATA__
  27. __C__
  28. void c_call(SV *obj, char *f) {
  29. dSP;
  30. ENTER;
  31. SAVETMPS;
  32. //XPUSHs(sv_2mortal(newSVpvf(obj)));
  33. //PUTBACK;
  34. call_pv(f, G_DISCARD);
  35. FREETMPS;
  36. LEAVE;
  37. }