Hi all, > You can access package variables directly: > > printf("here: %s\n", SvPV_nolen(get_sv("main::data",0)));
Wow OK - I didn't know you could do that. I'm wondering if this could be added into the Inline::C Cookbook? Perhaps under the heading "Accessing Perl variables directly from a C function". Rob, are you still maintaining Inline? Cheers, Ron. > On 30 Nov 2016, at 6:25 am, sisyph...@optusnet.com.au wrote: > > 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 > > >