-
Notifications
You must be signed in to change notification settings - Fork 0
/
evas_cb_helper.c
70 lines (59 loc) · 2.28 KB
/
evas_cb_helper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <Evas.h>
#include <parrot/parrot.h>
//Parrot_PMC hack_interp;
void
evas_cb_helper(Parrot_PMC user_data, Evas_Object *obj, void *event_info)
{
//Parrot_PMC pobj = pmc_new(hack_interp, enum_class_UnManagedStruct);
//Parrot_PMC pinfo = pmc_new(hack_interp, enum_class_UnManagedStruct);
//Parrot_PMC hash = pmc_new(hack_interp, enum_class_Hash);
Parrot_callback_C("oh noes", user_data);
}
Parrot_PMC make_evas_cb_helper(Parrot_Interp interp, Parrot_PMC sub, Parrot_PMC user_data, Parrot_String cb_signature)
{
Parrot_PMC cb, cb_sig, sync;
Parrot_String sc;
//hack_interp = interp;
/*
* we stuff all the information into the user_data PMC and pass that
* on to the external sub
*/
PMC * const interp_pmc = VTABLE_get_pmc_keyed_int(interp, interp->iglobals,
(INTVAL) IGLOBALS_INTERPRETER);
if (PMC_IS_NULL(interp_pmc)) {
fprintf(stderr,"Current interpreter is null!\n");
fflush(stderr);
}
else {
//Parrot_eprintf("");
}
/* be sure __LINE__ is consistent */
sc = Parrot_str_new_constant(interp, "_interpreter");
VTABLE_setprop(interp, user_data, sc, interp_pmc);
sc = Parrot_str_new_constant(interp, "_sub");
VTABLE_setprop(interp, user_data, sc, sub);
sc = Parrot_str_new_constant(interp, "_synchronous");
sync = pmc_new(interp, enum_class_Integer);
VTABLE_set_integer_native(interp, sync, 1);
VTABLE_setprop(interp, user_data, sc, sync);
cb_sig = pmc_new(interp, enum_class_String);
VTABLE_set_string_native(interp, cb_sig, cb_signature);
sc = Parrot_str_new_constant(interp, "_signature");
VTABLE_setprop(interp, user_data, sc, cb_sig);
/*
* We are going to be passing the user_data PMC to external code, but
* it may go out of scope until the callback is called -- we don't know
* for certain as we don't know when the callback will be called.
* Therefore, to prevent the PMC from being destroyed by a GC sweep,
* we need to anchor it.
*
*/
gc_register_pmc(interp, user_data);
/*
* Finally, the external lib awaits a function pointer.
*/
cb = pmc_new(interp, enum_class_UnManagedStruct);
VTABLE_set_pointer(interp, cb, F2DPTR(evas_cb_helper));
gc_register_pmc(interp, cb);
return cb;
}