/*
Copyright (C) 2005-2006, The Perl Foundation.
$Id: luafunction.pmc 17096 2007-02-20 20:20:48Z paultcochrane $

=head1 NAME

pmc/luafunction.pmc - Lua Function

=head1 DESCRIPTION

C<LuaFunction> extends C<Parrot Sub> and C<LuaAny> to provide a class
with the behaviour of the Lua C<Function> type.
C<LuaFunction> is used by standard libraries
written in PIR.

See also: F<languages/lua/pmc/luaclosure.pmc>

=head2 Overloaded Methods

=over 4

=cut

*/

#include "parrot/parrot.h"

static STRING *luafunction_name;
extern INTVAL dynpmc_LuaBoolean;


pmclass LuaFunction
    extends Sub
    extends LuaAny
    does scalar
    does sub
    dynpmc
    group lua_group
    hll Lua
    maps Sub {

/* Class initialization. Caches constant strings that will be used later.
*/
    void class_init() {
        if (pass) {
            luafunction_name = const_string(INTERP, "function");
        }
    }

/*

=item C<STRING* name()>

Return the string "function".

=cut

*/
    STRING* name () {
        return luafunction_name;
    }

/*

=item C<STRING* get_string()>

=cut

*/
    STRING* get_string () {
        return Parrot_sprintf_c(INTERP, "function: %08X", SELF);
    }

/*

=item C<INTVAL is_equal (PMC* value)>

=cut

*/
    INTVAL is_equal (PMC* value) {
MMD_LuaFunction: {
            return (PMC_sub(SELF))->start_offs == (PMC_sub(value))->start_offs
                && (PMC_sub(SELF))->seg == (PMC_sub(value))->seg;
        }
MMD_DEFAULT: {
            return (INTVAL)0;
        }
    }

/*

=back

=head2 Specific Methods

=over 4

=item C<PMC* rawequal (PMC* value)>

=cut

*/
    METHOD PMC* rawequal (PMC* value) {
        PMC *retval;

        retval = pmc_new(INTERP, dynpmc_LuaBoolean);
        if ( SELF->vtable->base_type == value->vtable->base_type
         && (PMC_sub(SELF))->start_offs == (PMC_sub(value))->start_offs
         && (PMC_sub(SELF))->seg == (PMC_sub(value))->seg )
            PMC_int_val(retval) = 1;
        else
            PMC_int_val(retval) = 0;
        return retval;
    }

}

/*

=back

=head1 AUTHORS

Francois Perrad

=cut

*/

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