]> 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/eval/eval.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 / eval / eval.c
1 /*
2 * Very simple example program for evaluating expressions from
3 * command line
4 */
5
6 #include "duktape.h"
7 #include <stdio.h>
8
9 static int eval_raw(duk_context *ctx) {
10 duk_eval(ctx);
11 return 1;
12 }
13
14 static int tostring_raw(duk_context *ctx) {
15 duk_to_string(ctx, -1);
16 return 1;
17 }
18
19 static void usage_exit(void) {
20 fprintf(stderr, "Usage: eval <expression> [<expression>] ...\n");
21 fflush(stderr);
22 exit(1);
23 }
24
25 int main(int argc, char *argv[]) {
26 duk_context *ctx;
27 int i;
28 const char *res;
29
30 if (argc < 2) {
31 usage_exit();
32 }
33
34 ctx = duk_create_heap_default();
35 for (i = 1; i < argc; i++) {
36 printf("=== eval: '%s' ===\n", argv[i]);
37 duk_push_string(ctx, argv[i]);
38 duk_safe_call(ctx, eval_raw, 1 /*nargs*/, 1 /*nrets*/);
39 duk_safe_call(ctx, tostring_raw, 1 /*nargs*/, 1 /*nrets*/);
40 res = duk_get_string(ctx, -1);
41 printf("%s\n", res ? res : "null");
42 duk_pop(ctx);
43 }
44
45 duk_destroy_heap(ctx);
46
47 return 0;
48 }