How to override invoke?
Andrew Whitworth
wknight8111 at gmail.com
Mon Dec 29 22:30:54 UTC 2008
The attached code works and does what you would think it should.
However, there is one snag:
$P0($P0)
This is because when you override the invoke vtable method from PIR,
you don't have access to the "self" pmc by default. You have to pass
it explicitly.
--Andrew Whitworth
.sub main :main
$P1 = compreg 'PIR'
$P2 = $P1(".sub a\nsay'hi from PIR'\n.end\n")
$P2 = $P2[0]
$P2()
$P0 = new 'MyProc'
assign $P0, $P2
$P0($P0)
.end
.namespace ['MyProc']
.sub class_init :anon :init
$P0 = get_class 'Sub'
$P1 = subclass $P0, 'MyProc'
addattribute $P1, 'RealSub'
.end
.sub invoke :vtable :method
.local pmc p
$P0 = getattribute self, 'RealSub'
say "First"
$P0()
say "Last"
.end
.sub assign_pmc :vtable :method
.param pmc p
setattribute self, 'RealSub', p
.end
More information about the parrot-dev
mailing list