]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/3rdparty/civetweb/src/third_party/duktape-1.5.2/examples/hello/hello.c
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / 3rdparty / civetweb / src / third_party / duktape-1.5.2 / examples / hello / hello.c
1 /*
2 * Very simple example program
3 */
4
5 #include "duktape.h"
6
7 int adder(duk_context *ctx) {
8 int i;
9 int n = duk_get_top(ctx); /* #args */
10 double res = 0.0;
11
12 for (i = 0; i < n; i++) {
13 res += duk_to_number(ctx, i);
14 }
15
16 duk_push_number(ctx, res);
17 return 1; /* one return value */
18 }
19
20 int main(int argc, char *argv[]) {
21 duk_context *ctx = duk_create_heap_default();
22
23 (void) argc; (void) argv; /* suppress warning */
24
25 duk_eval_string(ctx, "print('Hello world!');");
26
27 duk_push_global_object(ctx);
28 duk_push_c_function(ctx, adder, DUK_VARARGS);
29 duk_put_prop_string(ctx, -2, "adder");
30 duk_pop(ctx); /* pop global */
31
32 duk_eval_string(ctx, "print('2+3=' + adder(2, 3));");
33 duk_pop(ctx); /* pop eval result */
34
35 duk_destroy_heap(ctx);
36
37 return 0;
38 }