/* Copyright (C) 2006-2007, The Perl Foundation. $Id: luaclosure.pmc 21554 2007-09-25 13:55:52Z paultcochrane $ =head1 NAME pmc/luaclosure.pmc - Lua Closure =head1 DESCRIPTION C extends C and C to provide a class with the behaviour of the Lua C type. C is used by function written in Lua. See also: F =head2 Overloaded Methods =over 4 =cut */ #include "lua_private.h" pmclass LuaClosure extends Closure extends LuaAny does scalar does sub dynpmc need_ext group lua_group hll Lua maps Closure { /* =item C =cut */ void init_pmc(PMC* sub) { if (VTABLE_isa(INTERP, sub, const_string(INTERP, "Closure"))) { PMC_struct_val(SELF) = mem_allocate_typed(struct Parrot_sub); PMC_pmc_val(SELF) = PMCNULL; PMC_metadata(SELF) = PMCNULL; PObj_custom_mark_destroy_SETALL(SELF); /* copy the sub struct */ memcpy(PMC_sub(SELF), PMC_sub(sub), sizeof (struct Parrot_sub)); } else { real_exception(INTERP, NULL, E_Exception, "not a Closure (%s)", string_to_cstring(INTERP, SELF->vtable->whoami)); } } /* =item C Marks the closure as live. =cut */ void mark() { SUPER(); if (PMC_metadata(SELF)) pobject_lives(INTERP, (PObj *)PMC_metadata(SELF)); } /* =item C Return the string "function". =cut */ STRING* name() { return const_string(INTERP, "function"); } /* =item C =cut */ PMC* clone() { PMC* ret = SUPER(); PMC_metadata(ret) = PMC_metadata(SELF); return ret; } /* =item C =cut */ STRING* get_string() { return Parrot_sprintf_c(INTERP, "function: %08X", SELF); } /* =item C =cut */ void set_pmc(PMC *value) { PMC_struct_val(SELF) = PMC_struct_val(value); PMC_metadata(SELF) = PMC_metadata(value); } /* =item C =cut */ INTVAL is_equal(PMC* value) { MMD_LuaClosure: { 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 =cut */ METHOD PMC* getfenv() { PMC *retval = PMC_metadata(SELF); if (retval != NULL) return retval; else return pmc_new(INTERP, dynpmc_LuaNil); } /* =item C =cut */ METHOD PMC* rawequal(PMC* value) { PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean); if (PMC_type(SELF) == PMC_type(value) && (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; } /* =item C =cut */ METHOD void setfenv(PMC *env) { PMC_metadata(SELF) = env; } } /* =back =head1 AUTHORS Francois Perrad =cut */ /* * Local variables: * c-file-style: "parrot" * End: * vim: expandtab shiftwidth=4: */