line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include |
2
|
|
|
|
|
|
|
#include "pl_eventloop.h" |
3
|
|
|
|
|
|
|
#include "c_eventloop.h" |
4
|
|
|
|
|
|
|
|
5
|
263
|
|
|
|
|
|
int pl_register_eventloop(Duk* duk) |
6
|
|
|
|
|
|
|
{ |
7
|
|
|
|
|
|
|
/* Register our event loop dispatcher, otherwise calls to */ |
8
|
|
|
|
|
|
|
/* dispatch_function_in_event_loop will not work. */ |
9
|
263
|
|
|
|
|
|
eventloop_register(duk->ctx); |
10
|
263
|
|
|
|
|
|
return 0; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
|
|
|
int pl_run_function_in_event_loop(Duk* duk, const char* func) |
14
|
|
|
|
|
|
|
{ |
15
|
3
|
|
|
|
|
|
duk_context* ctx = duk->ctx; |
16
|
3
|
|
|
|
|
|
duk_int_t rc = 0; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
/* Start a zero timer which will call our function from the event loop. */ |
19
|
3
|
|
|
|
|
|
duk_push_sprintf(ctx, "setTimeout(function() { %s(); }, 0);", func); |
20
|
3
|
|
|
|
|
|
rc = duk_peval(ctx); |
21
|
3
|
50
|
|
|
|
|
if (rc != DUK_EXEC_SUCCESS) { |
22
|
0
|
|
|
|
|
|
croak("Could not eval JS event loop dispatcher for %s: %d - %s\n", |
23
|
|
|
|
|
|
|
func, rc, duk_safe_to_string(ctx, -1)); |
24
|
|
|
|
|
|
|
} |
25
|
3
|
|
|
|
|
|
duk_pop(ctx); /* pop result / error */ |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
/* Launch eventloop; this call only returns after the eventloop terminates. */ |
28
|
3
|
|
|
|
|
|
rc = duk_safe_call(ctx, eventloop_run, duk, 0 /*nargs*/, 1 /*nrets*/); |
29
|
3
|
50
|
|
|
|
|
if (rc != DUK_EXEC_SUCCESS) { |
30
|
0
|
|
|
|
|
|
croak("JS event loop run failed: %d - %s\n", |
31
|
|
|
|
|
|
|
rc, duk_safe_to_string(ctx, -1)); |
32
|
|
|
|
|
|
|
} |
33
|
3
|
|
|
|
|
|
duk_pop(ctx); |
34
|
|
|
|
|
|
|
|
35
|
3
|
|
|
|
|
|
return 0; |
36
|
|
|
|
|
|
|
} |