cheax
Lisp dialect with C API
Setup and configuration

Functions and datastructures to initialize, clean up and configure a cheax virtual machine instance. More...

Collaboration diagram for Setup and configuration:

Data Structures

struct  chx_config_help
 Information about cheax config option. More...
 

Functions

CHEAXcheax_init (void)
 Initializes a new cheax virtual machine instance. More...
 
const char * cheax_version (void)
 Returns cheax library version as a string in the static storage class. More...
 
int cheax_load_feature (CHEAX *c, const char *feat)
 Loads extra functions or language features into the cheax environment, including 'unsafe' ones. More...
 
int cheax_load_prelude (CHEAX *c)
 Loads the cheax standard library. More...
 
void cheax_destroy (CHEAX *c)
 Destroys a cheax virtual machine instance, freeing its resources. More...
 
int cheax_config_get_int (CHEAX *c, const char *opt)
 Get value of integer configuration option. More...
 
int cheax_config_int (CHEAX *c, const char *opt, int value)
 Set value of integer configuration option. More...
 
bool cheax_config_get_bool (CHEAX *c, const char *opt)
 Get value of boolean configuration option. More...
 
int cheax_config_bool (CHEAX *c, const char *opt, bool value)
 Set value of boolean configuration option. More...
 
int cheax_config_help (struct chx_config_help **help, size_t *num_opts)
 Load information about all cheax config options. More...
 

Detailed Description

Functions and datastructures to initialize, clean up and configure a cheax virtual machine instance.

Function Documentation

◆ cheax_init()

CHEAX* cheax_init ( void  )

Initializes a new cheax virtual machine instance.

See also
cheax_load_features(), cheax_load_prelude(), cheax_destroy(), cheax_version()

◆ cheax_version()

const char* cheax_version ( void  )

Returns cheax library version as a string in the static storage class.

◆ cheax_load_feature()

int cheax_load_feature ( CHEAX c,
const char *  feat 
)

Loads extra functions or language features into the cheax environment, including 'unsafe' ones.

Supported values for feat are:

  • "file-io" to load fopen and fclose built-ins;
  • "set-max-stack-depth" to load the set-max-stack-depth built-in;
  • "gc" to load the gc built-in function;
  • "exit" to load the exit function;
  • "stdin" to expose the stdin variable;
  • "stdout" to expose the stdout variable;
  • "stderr" to expose the stderr variable;
  • "stdio" to expose stdin, stdout and stderr;
  • "all" to load every feature available (think twice before using).

A feature can only be loaded once. Attempting to load a feature more than once will cause no action.

Parameters
featWhich feature to load.
Returns
0 if the given feature was loaded successfully, or -1 if the given feature is not supported.

◆ cheax_load_prelude()

int cheax_load_prelude ( CHEAX c)

Loads the cheax standard library.

Sets cheax_errno() to CHEAX_EAPI if the standard library could not be found.

Returns
0 if everything succeeded without errors, -1 if there was an error finding or loading the standard library.

◆ cheax_destroy()

void cheax_destroy ( CHEAX c)

Destroys a cheax virtual machine instance, freeing its resources.

Any use of c after calling cheax_destroy() on it results in undefined behavior.

◆ cheax_config_get_int()

int cheax_config_get_int ( CHEAX c,
const char *  opt 
)

Get value of integer configuration option.

Sets cheax_errno() to CHEAX_EAPI if no option of integer type with name opt exists.

Parameters
optOption name.
Returns
Option value, or 0 upon failure.

◆ cheax_config_int()

int cheax_config_int ( CHEAX c,
const char *  opt,
int  value 
)

Set value of integer configuration option.

Sets cheax_errno() to CHEAX_EAPI if option opt does not have integer type, or if value is otherwise invalid for option opt. Fails silently in case no option with name opt could be found.

Parameters
optOption name.
valueOption value.
Returns
0 if an integer option with name opt was found, -1 otherwise.

◆ cheax_config_get_bool()

bool cheax_config_get_bool ( CHEAX c,
const char *  opt 
)

Get value of boolean configuration option.

Sets cheax_errno() to CHEAX_EAPI if no option of boolean type with name opt exists.

Parameters
optOption name.
Returns
Option value, or false upon failure.

◆ cheax_config_bool()

int cheax_config_bool ( CHEAX c,
const char *  opt,
bool  value 
)

Set value of boolean configuration option.

Sets cheax_errno() to CHEAX_EAPI if option opt does not have boolean type, or if value is otherwise invalid for option opt. Fails silently in case no option with name opt could be found.

Parameters
optOption name.
valueOption value.
Returns
0 if a boolean option with name opt was found, -1 otherwise.

◆ cheax_config_help()

int cheax_config_help ( struct chx_config_help **  help,
size_t *  num_opts 
)

Load information about all cheax config options.

Parameters
helpOutput parameter. Make sure to free() after use.
num_optsOutput parameter, will point to length of output array.
Returns
0 if everything succeeded without errors, -1 otherwise.