/*
Copyright (C) 2001-2006, The Perl Foundation.
$Id: perlenv.pmc 16836 2007-01-30 04:30:52Z coke $

=head1 NAME

src/dynpmc/perlenv.pmc - Perl System Environment

=head1 DESCRIPTION

C<PerlEnv> extends C<Env> to return scalars from C<get_pmc_keyed()>.

=head2 Methods

=over 4

=cut

*/

#include "parrot/parrot.h"

static PMC * Env_PMC;

pmclass PerlEnv
    singleton
    dynpmc
    group perl_group
    extends Env {

/*

=item C<void *get_pointer()>

=cut

*/

void* get_pointer() {
        return Env_PMC;
    }

/*

=item C<void set_pointer(void *ptr)>

Gets and sets the pointer to the singleton instance. See F<src/pmc.c>
for more information on the singleton creation interface.

=cut

*/

    void set_pointer(void* ptr) {
        Env_PMC = (PMC*) ptr;
    }

/*

=item C<PMC *get_pmc_keyed(PMC *key)>

Returns the result of C<get_string_keyed(key)> as a C<PerlString>.

=cut

*/

    PMC* get_pmc_keyed(PMC* key) {
        INTVAL   dynpmc_PerlString;
        PMC     *ret;
        STRING  *string;

        dynpmc_PerlString = pmc_type(interp,
            string_from_const_cstring(interp, "PerlString", 0));
        ret = pmc_new(INTERP, dynpmc_PerlString);
        string = DYNSELF.get_string_keyed(key);
        VTABLE_set_string_native(INTERP, ret, string);

        return ret;
    }

/*

=item C<void set_pmc_keyed(PMC *key, PMC *value)>

Returns the result of calling C<set_string_keyed()> with C<*value>
converted to a Parrot string.

=cut

*/

    void set_pmc_keyed(PMC* key, PMC* value) {
        DYNSELF.set_string_keyed(key, VTABLE_get_string(INTERP, value));
    }
}

/*

=back

=cut

*/

/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
