2 Copyright (C) 2005-2008, The Perl Foundation.
7 pmc/luathread.pmc - Lua Thread
11 C<LuaThread> extends C<LuaAny> to provide a class with the behaviour
12 of the Lua C<Thread> type.
13 This implementation is based on C<Parrot::Coroutine>.
15 =head2 Overloaded Methods
23 #include "lua_private.h"
25 static PMC* curr_func(PARROT_INTERP) {
26 parrot_context_t *ctx = CONTEXT(interp);
27 PMC *sub = ctx->current_sub;
31 static PMC* getcurrenv(PARROT_INTERP) {
33 PMC *sub = curr_func(interp);
35 env = PMC_metadata(sub);
52 Raises an exception. Use C<init_pmc()>.
58 real_exception(INTERP, NULL, E_Exception,
59 "LuaThread init without sub");
64 =item C<void init_pmc(PMC *sub)>
69 void init_pmc(PMC *sub) {
70 PMC *classobj = Parrot_oo_get_class_str(INTERP,
71 const_string(INTERP, "Parrot::Coroutine"));
74 if (PMC_IS_NULL(classobj))
75 real_exception(INTERP, NULL, E_Exception,
76 "Parrot::Coroutine not found");
78 init_args = pmc_new(INTERP, enum_class_Hash);
79 VTABLE_set_pmc_keyed_str(INTERP, init_args,
80 const_string(INTERP, "initial_sub"), sub);
81 PMC_pmc_val(SELF) = VTABLE_instantiate(INTERP, classobj, init_args);
82 PMC_metadata(SELF) = getcurrenv(INTERP);
83 PObj_custom_mark_SET(SELF);
90 Marks the Parrot::Coroutine as live.
96 if (PMC_pmc_val(SELF))
97 pobject_lives(INTERP, (PObj *)PMC_pmc_val(SELF));
98 if (PMC_metadata(SELF))
99 pobject_lives(INTERP, (PObj *)PMC_metadata(SELF));
104 =item C<STRING* name()>
106 Return the string "thread".
112 return const_string(INTERP, "thread");
117 =item C<PMC* clone()>
128 =item C<PMC* get_attr_str(STRING *key)>
133 PMC* get_attr_str(STRING *key) {
134 return PMC_pmc_val(SELF);
139 =item C<STRING* get_string()>
144 STRING* get_string() {
145 return Parrot_sprintf_c(INTERP, "thread: %08X", SELF);
150 =item C<void set_pmc(PMC *value)>
155 void set_pmc(PMC *value) {
156 PMC_pmc_val(SELF) = PMC_pmc_val(value);
163 =head2 non-Vtable Methods
167 =item C<INTVAL is_equal(PMC *value)>
172 INTVAL is_equal(PMC *value) {
188 =head2 Specific Methods
192 =item C<PMC *getfenv()>
197 METHOD PMC* getfenv() {
198 PMC *retval = PMC_metadata(SELF);
201 retval = pmc_new(INTERP, dynpmc_LuaNil);
208 =item C<PMC* rawequal(PMC *value)>
213 METHOD PMC* rawequal(PMC *value) {
214 PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean);
216 if (PMC_type(SELF) == PMC_type(value) && SELF == value)
217 VTABLE_set_integer_native(INTERP, retval, 1);
219 VTABLE_set_integer_native(INTERP, retval, 0);
226 =item C<void setfenv(PMC *env)>
231 METHOD void setfenv(PMC *env) {
232 PMC_metadata(SELF) = env;
251 * c-file-style: "parrot"
253 * vim: expandtab shiftwidth=4: