Hi,
You can also access the string in $data from C with (untested):
SvPV_nolen(get_sv(main::data,0));
See 'perldoc perlapi' (or maybe it's in 'perldoc perlcall').
Cheers,
Rob
From: Ron Grunwald via inline
Sent: Wednesday, November 30, 2016 1:10 AM
To: Perf Tech ; inline@perl.org
Subject: Re: Question about accessing global data from a line function
Hi Jin,
I don’t think you can access perl variables this way because your C function
needs some sort of reference to them. Change your code to,
$data = "this is a test";
test($data);
use Inline C => <<'END_OF_C_CODE';
void test(SV* data) {
printf("here: %s\n", SvPV(data, PL_na));
}
END_OF_C_CODE
Cheers,
Ron.
On 23 Nov 2016, at 1:29 pm, Perf Tech <perfte...@gmail.com> wrote:
Dear expert,
I am trying to access perl global variable ($data in this case) from
within a inline C function, but the "data" variable I used is not defined.
Any idea how to do it?
Thanks
Jin
$data = "this is a test";
test();
use Inline C => <<'END_OF_C_CODE';
void test() {
printf("here: %s\n", SvPV(data, PL_na));
}
END_OF_C_CODE