On Mon, Feb 11, 2008 at 10:27:27PM +0100, Andrew Parker wrote:
> .namespace
> .sub "outer"
>     new $P12, "Integer"
>     assign $P12, 1
>     .lex "x", $P12
>     get_global $P18, "inner"
>     newclosure $P18, $P18
>     $P17 = $P18()
>     print $P17
>     print "\n"
> .end
> 
> .sub "inner"  :outer("outer")
>     find_lex $P14, "x"
>     n_add $P15, $P14, 1
>     .lex "x", $P15
>     .return ($P15)
> .end

A PIR subroutine can get at its caller's lexpad by doing:

    $P0 = getinterp
    $P1 = $P0['lexpad'; 1]

So, in the 'inner' sub above, it can get to outer's 'x' lexical
by doing:

    $P0 = getinterp
    $P1 = $P0['lexpad'; 1]
    $P2 = $P1['x']

Pm

Reply via email to