cheax
Lisp dialect with C API
cheax

Build status

A Lisp dialect that looks a bit like Haskell. Designed for easy interoperability with C/C++.

Installation

$ mkdir build && cd build && cmake .. && make
# make install

Language demo

Made with VHS

C API example

#include <cheax.h>
#include <stdio.h>
int main(void)
{
int result;
CHEAX *c = cheax_init();
/* Load some "unsafe" functions, e.g. file io and the program
* exit function */
cheax_load_feature(c, "all");
/* Make sure cheax doesn't cause a stack overflow */
cheax_config_int(c, "stack-limit", 4096);
/* Load the standard library */
if (cheax_load_prelude(c) < 0) {
/* Display error message on behalf of "example" program */
cheax_perror(c, "example");
return EXIT_FAILURE;
}
/* Synchronize variable `result' with the eponymous symbol
* in cheax */
cheax_sync_int(c, "result", &result, 0);
cheax_eval(c, cheax_readstr(c, "(set result (sum (.. 1 100)))"));
printf("1 + 2 + ... + 100 = %d\n", result);
return 0;
}
The header for the cheax C API.
void cheax_sync_int(CHEAX *c, const char *name, int *var, int flags)
Synchronizes a variable from C with a symbol in the cheax environment.
struct chx_value cheax_readstr(CHEAX *c, const char *str)
Reads value from string.
struct chx_value cheax_eval(CHEAX *c, struct chx_value expr)
Evaluates given cheax expression.
struct cheax CHEAX
The type of the cheax virtual machine state, a pointer to wich is needed for most cheax API functions...
Definition: cheax.h:38
void cheax_perror(CHEAX *c, const char *s)
Prints the current cheax error code and error message.
void cheax_destroy(CHEAX *c)
Destroys a cheax virtual machine instance, freeing its resources.
int cheax_load_feature(CHEAX *c, const char *feat)
Loads extra functions or language features into the cheax environment, including 'unsafe' ones.
int cheax_config_int(CHEAX *c, const char *opt, int value)
Set value of integer configuration option.
CHEAX * cheax_init(void)
Initializes a new cheax virtual machine instance.
int cheax_load_prelude(CHEAX *c)
Loads the cheax standard library.