develooper Front page | perl.perl6.internals | Postings from October 2002

PMC initializer stuff

Thread Next
Dan Sugalski
October 18, 2002 09:22
PMC initializer stuff
Message ID:
Okay, it's been a while, I've been out of it, it's time to start getting going.

Today's first topic: PMCs with real initializers. Here's a snip from 
the updated PDD2:


=item void init_pmc(INTERP, PMC* self, PMC* initializer)

This form of the init method takes a single initializer parameter. The
initializer is an array that contains keys and values. The meaning of
the keys and their corresponding values is left up to the PMC.

Keys are either strings or integers. If strings, the PMC is
responsible for figuring out what the string represents. If integers,
it means the meaning has been pre-figured based on meta-information
from the class.

For example, if a class has the known properties "Size", "Dimension"
and "Color", they may be assigned the values 100, 101, and 102. If the
creator if the PMC knows enough about the class to make the
translation to numbers it may, otherwise the strings may be used. So
for the declaration:

    my @foo is Size(12) is Dimension(3) is Color("Green");

the init array may be [100, 12, 101, 3, 102, "Green"] or ["Size", 12,
"Dimension", 3, "Color", "Green"]. Note that, in all cases, the array
is an array of PMCs. (So you get either an int PMC or a string PMC in
the list of keys)


We still have the plain init call for cases where we're not doing 
anything special.

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai                         have teddy bears and even
                                       teddy bears get drunk

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About