Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get integer out of an IV* in Perl

Tags:

c

perl

Is there a macro or function in the Perl API for getting the actual integer field of a IV*? I can find tons of information for getting at just about every other kind of value in perlguts and perlapi but this one seems to elude me.

like image 952
friedo Avatar asked Mar 23 '23 19:03

friedo


1 Answers

From perlguts SvIV(SV*) should do the trick.

#!/usr/bin/env perl

use strict;
use warnings;

use Inline C => <<'END';
void print_iv (SV* input) {
  if (! SvIOK(input))
    croak("Not an integer");
  printf("Printing integer %d\n", SvIV(input));
}
END

print_iv(3);
like image 121
Joel Berger Avatar answered Apr 02 '23 12:04

Joel Berger