On Mon, Jan 09, 2006 at 06:11:59PM -0500, Steven N. Hirsch wrote: > 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
Careful. Some people won't talk very nicely of you if you go bandying URLs like that around. > > 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. You could take a look at the code in PadWalker on CPAN to get some ideas, I think. > 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. The docs (used to?) talk about closures being anonymous subroutines, but I think most people nowadays would says that mysub closes over $variable and hence it is a closure. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net