2 Copyright (C) 2006-2008, The Perl Foundation.
7 pmc/luaclosure.pmc - Lua Closure
11 C<LuaClosure> extends C<Parrot Closure> and C<LuaAny> to provide a class with
12 the behaviour of the Lua C<Function> type. C<LuaClosure> is used by functions
15 See also: F<languages/lua/pmc/luafunction.pmc>
17 =head2 Overloaded Methods
25 #include "lua_private.h"
41 =item C<void init_pmc(PMC *sub)>
46 void init_pmc(PMC *sub) {
47 if (VTABLE_isa(INTERP, sub, const_string(INTERP, "Closure"))) {
48 PMC_struct_val(SELF) = mem_allocate_zeroed_typed(Parrot_sub);
49 PMC_pmc_val(SELF) = NULL;
50 PMC_metadata(SELF) = NULL;
51 PObj_custom_mark_destroy_SETALL(SELF);
52 /* copy the sub struct */
53 memcpy(PMC_sub(SELF), PMC_sub(sub), sizeof (Parrot_sub));
56 real_exception(INTERP, NULL, E_Exception, "not a Closure (%Ss)",
57 string_to_cstring(INTERP, SELF->vtable->whoami));
64 Marks the closure as live.
71 if (PMC_metadata(SELF))
72 pobject_lives(INTERP, (PObj *)PMC_metadata(SELF));
77 =item C<STRING* name()>
79 Return the string "function".
85 return const_string(INTERP, "function");
97 PMC_metadata(ret) = PMC_metadata(SELF);
98 PObj_custom_mark_destroy_SETALL(ret);
104 =item C<STRING* get_string()>
109 STRING* get_string() {
110 return Parrot_sprintf_c(INTERP, "function: %08X", SELF);
115 =item C<void set_pmc(PMC *value)>
120 void set_pmc(PMC *value) {
121 PMC_struct_val(SELF) = PMC_struct_val(value);
122 PMC_metadata(SELF) = PMC_metadata(value);
127 =item C<INTVAL is_equal(PMC* value)>
132 INTVAL is_equal(PMC* value) {
134 return (PMC_sub(SELF))->start_offs == (PMC_sub(value))->start_offs
135 && (PMC_sub(SELF))->seg == (PMC_sub(value))->seg;
146 =head2 Specific Methods
150 =item C<PMC *getfenv()>
155 METHOD PMC* getfenv() {
156 PMC *retval = PMC_metadata(SELF);
159 retval = pmc_new(INTERP, dynpmc_LuaNil);
166 =item C<PMC* rawequal(PMC* value)>
171 METHOD PMC* rawequal(PMC* value) {
172 PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean);
174 if (PMC_type(SELF) == PMC_type(value)
175 && (PMC_sub(SELF))->start_offs == (PMC_sub(value))->start_offs
176 && (PMC_sub(SELF))->seg == (PMC_sub(value))->seg)
177 VTABLE_set_integer_native(INTERP, retval, 1);
179 VTABLE_set_integer_native(INTERP, retval, 0);
186 =item C<void setfenv(PMC *env)>
191 METHOD void setfenv(PMC *env) {
192 PMC_metadata(SELF) = env;
211 * c-file-style: "parrot"
213 * vim: expandtab shiftwidth=4: