commit 3496656
uint
·
2026-10-24 16:21:49 +0000 UTC
parent da339c2
Add Usage in README
1 files changed,
+54,
-0
+54,
-0
1@@ -6,3 +6,57 @@ larger configuration languages.
2
3 For maximum compatibility, it's written in ANSI C.
4
5+#### Usage
6+An extract from `expl.c`:
7+
8+``` c
9+static expl_value
10+birds_who_hit_my_window(int argc, const expl_value* argv, void* data)
11+{
12+ int* count = (int*)data;
13+ expl_value result = { 0 };
14+
15+ if (argc == 1 && argv[0].type == EXPL_VALUE_NUMBER)
16+ *count += (int)argv[0].as.number;
17+
18+ result.type = EXPL_VALUE_NUMBER;
19+ result.as.number = *count;
20+
21+ return result;
22+}
23+
24+#define FIND_THE_BIRDS \
25+"(fn foo (x) (birds_who_hit_window x))\n" \
26+"(foo 134)\n"
27+
28+int
29+main(void)
30+{
31+ int birds_who_hit_my_window_c = 0;
32+ expl* ctx = expl_init();
33+
34+ if (!ctx)
35+ return EXIT_FAILURE;
36+
37+ expl_register(ctx, "birds_who_hit_my_window", birds_who_hit_my_window, &birds_who_hit_my_window_c);
38+ expl_run(ctx, FIND_THE_BIRDS);
39+ printf("Stupid birds: %d\n", birds_who_hit_my_window_c);
40+
41+ expl_close(ctx);
42+ return EXIT_SUCCESS;
43+}
44+```
45+
46+And an `expl_value` is defined as:
47+
48+``` c
49+struct expl_value {
50+ expl_value_type type;
51+ union {
52+ double number;
53+ char* string;
54+ void* function;
55+ } as;
56+};
57+```
58+