master expl.h
 1#ifndef EXPL_H
 2#define EXPL_H
 3
 4typedef enum {
 5	EXPL_VALUE_NIL,
 6	EXPL_VALUE_NUMBER,
 7	EXPL_VALUE_STRING,
 8	EXPL_VALUE_FUNCTION,
 9
10	EXPL_VALUE_COUNT
11} expl_value_type;
12
13typedef enum {
14	EXPL_ERR_NONE,
15	EXPL_ERR_EXPECTED_ATOM,
16	EXPL_ERR_EXPECTED_STRING,
17	EXPL_ERR_EXPECTED_LIST,
18	EXPL_ERR_UNEXPECTED_TOKEN,
19	EXPL_ERR_OUT_OF_MEMORY,
20
21	EXPL_ERR_COUNT
22} expl_error;
23
24typedef struct expression expression;
25typedef struct expl_value expl_value;
26typedef struct expl expl;
27
28typedef expl_value (*expl_native)(int argc, const expl_value* argv, void* data);
29
30struct expl_value {
31	expl_value_type type;
32	union {
33		double number;
34		char*  string;
35		void*  function;
36	} as;
37};
38
39/* create a new context and initialize it
40   returns context on success, NULL on failure */
41expl* expl_init(void);
42
43/* free given context and resources */
44void expl_close(expl* ctx);
45
46/* register a native function in the given context
47   returns 1 on success, 0 on failure */
48int expl_register(expl* ctx, const char* name, expl_native fn, void* data);
49
50/* run the source code in the given context
51   returns the result of expression evaluated, return->type is EXPL_VALUE_NIL on
52   failure */
53expl_value expl_run(expl* ctx, const char* source);
54
55#endif /* EXPL_H */
56