On Mon, 9 Jan 2006, Jeremy White wrote:

> Given this code:
> 
> {
> my $variable;
> sub mysub {
>    # ... accessing $variable
>    }
> }
> 
> from:
> 
> http://www.unix.org.ua/orelly/perl/cookbook/ch10_04.htm
> 
> Is there a way to get hold of the SV for $variable and manipulate it via XS?
> 
> I want to be able to write the contents of $variable in XS, then call mysub
> via XS and then read the contents of $variable afterwards ($variable needs to
> remain a closure as it is shared with other subs in the same block - the block
> is evaled into existence during runtime).

Since lexical variables don't appear in the symbol table, the only way I 
know of to access it from XS would be to stash a reference somewhere and 
pass that to the XS routine.  Also, I may have simply been up too long, 
but I don't believe your example represents a closure.  Only (1) instance 
of 'mysub' will exist and it's present in the package's symbol table.  

Steve


Reply via email to