]>
git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/src/third_party/duktape-1.5.2/examples/guide/processlines.c
7 int main(int argc
, const char *argv
[]) {
8 duk_context
*ctx
= NULL
;
13 ctx
= duk_create_heap_default();
15 printf("Failed to create a Duktape heap.\n");
19 if (duk_peval_file(ctx
, "process.js") != 0) {
20 printf("Error: %s\n", duk_safe_to_string(ctx
, -1));
23 duk_pop(ctx
); /* ignore result */
25 memset(line
, 0, sizeof(line
));
28 if (idx
>= sizeof(line
)) {
29 printf("Line too long\n");
37 duk_push_global_object(ctx
);
38 duk_get_prop_string(ctx
, -1 /*index*/, "processLine");
39 duk_push_string(ctx
, line
);
40 if (duk_pcall(ctx
, 1 /*nargs*/) != 0) {
41 printf("Error: %s\n", duk_safe_to_string(ctx
, -1));
43 printf("%s\n", duk_safe_to_string(ctx
, -1));
45 duk_pop(ctx
); /* pop result/error */
48 } else if (ch
== EOF
) {
51 line
[idx
++] = (char) ch
;
56 duk_destroy_heap(ctx
);