Tagging trunk at r29452 so that the noautopack can later be synched to it.
[parrot.git] / languages / lua / src / pmc / luafunction.pmc
blobfedd388e7886415b4bca958a8bd55b4fb67ed67b
1 /*
2 Copyright (C) 2005-2008, The Perl Foundation.
3 $Id$
5 =head1 NAME
7 pmc/luafunction.pmc - Lua Function
9 =head1 DESCRIPTION
11 C<LuaFunction> extends C<Parrot Sub> and C<LuaAny> to provide a class
12 with the behaviour of the Lua C<Function> type.
13 C<LuaFunction> is used by standard libraries
14 written in PIR.
16 See also: F<languages/lua/pmc/luaclosure.pmc>
18 =head2 Overloaded Methods
20 =over 4
22 =cut
26 #include "lua_private.h"
29 pmclass LuaFunction
30     extends  Sub
31     extends  LuaAny
32     provides scalar
33     provides sub
34     dynpmc
35     need_ext
36     group    lua_group
37     hll      Lua
38     maps     Sub {
42 =item C<void mark()>
44 Marks the function as live.
46 =cut
49     void mark() {
50         SUPER();
51         if (PMC_metadata(SELF))
52             pobject_lives(INTERP, (PObj *)PMC_metadata(SELF));
53     }
57 =item C<STRING* name()>
59 Return the string "function".
61 =cut
64     STRING* name() {
65         return const_string(INTERP, "function");
66     }
70 =item C<PMC *clone()>
72 =cut
75     PMC* clone() {
76         PMC* ret = SUPER();
77         PMC_metadata(ret) = PMC_metadata(SELF);
78         PObj_custom_mark_SET(ret);
79         return ret;
80     }
84 =item C<STRING* get_string()>
86 =cut
89     STRING* get_string() {
90         return Parrot_sprintf_c(INTERP, "function: %08X", SELF);
91     }
95 =item C<void set_pmc(PMC *value)>
97 =cut
100     void set_pmc(PMC *value) {
101         PMC_struct_val(SELF) = PMC_struct_val(value);
102         PMC_metadata(SELF)   = PMC_metadata(value);
103     }
107 =item C<INTVAL is_equal(PMC *value)>
109 =cut
112     INTVAL is_equal(PMC *value) {
113 MMD_LuaFunction: {
114             return (PMC_sub(SELF))->start_offs == (PMC_sub(value))->start_offs
115                 && (PMC_sub(SELF))->seg        == (PMC_sub(value))->seg;
116         }
117 MMD_DEFAULT: {
118             return (INTVAL)0;
119         }
120     }
124 =back
126 =head2 Specific Methods
128 =over 4
130 =item C<PMC *getfenv()>
132 =cut
135     METHOD PMC* getfenv() {
136         PMC *retval = PMC_metadata(SELF);
138         if (!retval)
139             retval = pmc_new(INTERP, dynpmc_LuaNil);
141         RETURN(PMC *retval);
142     }
146 =item C<PMC* rawequal(PMC *value)>
148 =cut
151     METHOD PMC* rawequal(PMC *value) {
152         PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean);
154         if (PMC_type(SELF)             == PMC_type(value)
155         && (PMC_sub(SELF))->start_offs == (PMC_sub(value))->start_offs
156         && (PMC_sub(SELF))->seg        == (PMC_sub(value))->seg)
157             VTABLE_set_integer_native(INTERP, retval, 1);
158         else
159             VTABLE_set_integer_native(INTERP, retval, 0);
161         RETURN(PMC *retval);
162     }
166 =item C<void setfenv(PMC *env)>
168 =cut
171     METHOD void setfenv(PMC *env) {
172         PMC_metadata(SELF) = env;
173     }
179 =back
181 =head1 AUTHORS
183 Francois Perrad
185 =cut
190  * Local variables:
191  *   c-file-style: "parrot"
192  * End:
193  * vim: expandtab shiftwidth=4:
194  */