Factor embedding API
Factor handbook > C library interface > Embedding Factor into C applications

Next:What embedding looks like from Factor


The Factor embedding API is defined in vm/master.h.

The F_CHAR type is an alias for the character type used for path names by the operating system; char on Unix and wchar_t on Windows.

Including this header file into a C compilation unit will declare the following functions:
void init_factor_from_args( F_CHAR *image, int argc, F_CHAR **argv, bool embedded )

Initializes Factor.

If image is NULL, Factor will load an image file whose name is obtained by suffixing the executable name with .image.

The argc and argv parameters are interpreted just like normal command line arguments when running Factor stand-alone; see Command line arguments.

The embedded flag ensures that this function returns as soon as Factor has been initialized. Otherwise, Factor will start up normally.
char *factor_eval_string(char *string)

Evaluates a piece of code in the embedded Factor instance by passing the string to eval>string and returning the result. The result must be explicitly freed by a call to factor_eval_free.
void factor_eval_free(char *result)

Frees a string returned by factor_eval_string().
void factor_yield(void)

Gives all Factor threads a chance to run.
void factor_sleep(long us)

Gives all Factor threads a chance to run for us microseconds.