FUNCTION:
Factor handbook » C library interface » Calling C from Factor

Prev:LIBRARY:
Next:FUNCTION-ALIAS:


Vocabulary
alien.syntax

Syntax
FUNCTION: return name ( parameters )


Inputs
None

Outputs
None

Word description
Defines a new word name which calls the C library function with the same name in the logical library given by the most recent LIBRARY: declaration.

The new word must be compiled before being executed.

Examples
For example, suppose the foo library exports the following function:
void the_answer(char* question, int value) { printf("The answer to %s is %d. ",question,value); }

You can define a word for invoking it:
LIBRARY: foo FUNCTION: void the_answer ( c-string question, int value ) "the question" 42 the_answer
The answer to the question is 42.

Using the c-string type instead of char* causes the FFI to automatically convert Factor strings to C strings. See C strings for more information on using strings with the FFI.

Notes
To make a Factor word with a name different from the C function, use FUNCTION-ALIAS:.

See also
FUNCTION-ALIAS:

Definition