In other words, I know I can use <store_global> to add the subroutine
into the current namespace...
.namespace [ "Foo" ]
.sub main @MAIN
$S0 = ".sub h @ANON\n print \"Hello\"\n.end\n"
$P0 = compreg "PIR"
$P1 = compile $P0, $S0
store_global "Foo", "hello", $P1
"hello"()
.end
but is there a way for me to store such a subroutine as a method of an
existing class? I.e., I'd like to be able to do something along
the lines of:
.sub main @MAIN
$P99 = newclass "Foo"
$S0 = ".sub h @ANON\n print \"Hello\"\n.end\n"
$P0 = compreg "PIR"
$P1 = compile $P0, $S0
store_global "Foo", "hello", $P1
$I2 = findclass "Foo"
$P2 = new $I2
$P2."hello"()
.end
Am I totally off-the-wall here, or am I just overlooking a pragma, opcode,
or something similar that would allow this to work?
Pm
> ... I.e., I'd like to be able to do something along
> the lines of:
>
> .sub main @MAIN
> $P99 = newclass "Foo"
>
> $S0 = ".sub h @ANON\n print \"Hello\"\n.end\n"
> $P0 = compreg "PIR"
> $P1 = compile $P0, $S0
> store_global "Foo", "hello", $P1
>
> $I2 = findclass "Foo"
> $P2 = new $I2
> $P2."hello"()
> .end
That works fine if you s/findclass/find_type/
C<findclass> is one of the ugly/evil/wrong opcode warts that will be
removed soon. It duplicates the functionality of C<find_type> with
restricted usage (returns a *boolean*) and inconsistent syntax.
leo
Excellent! For some reason I thought it didn't work for me even
when I tried find_type, but it seems to be working now. This
simplifies things a lot -- thanks!
Pm