Re: Accessing variables from inside a C-XS

[email protected] (Oliver Seeliger)
Newsgroups perl.xs
Message-ID <[email protected]>
Hi Josef,

 > I'd like to access a Perl-variable (a scalar) from within an XS. I do
 > accept that the scalar may not (yet) exists, so I'd cater for that:
 >
 > How do I do that:
 > - find out if a scalar exists
 > - access the contents of the scalar.

If you know the name of a scalar variable, you can get a pointer to its 
SV by using the following:

     SV*  perl_get_sv("package::varname", FALSE);

This returns NULL if the variable does not exist.

If you want to know if this variable (or any other SV) is actually 
defined, you can call:

     SvOK(SV*)

http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perlguts.html

Hope this helps.

Cheers,
Olli
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.