Vocabularyalien.syntaxSyntaxFUNCTION: return name ( parameters ) ;
Inputs and outputs| return | a C return type |
| name | a C function name |
| parameters | a comma-separated sequence of type/name pairs; type1 arg1, type2 arg2, ... |
Word descriptionDefines 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.
ExamplesFor 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.
NotesNote that the parentheses and commas are only syntax sugar and can be omitted; they serve no purpose other than to make the declaration easier to read. The following definitions are equivalent:
FUNCTION: void glHint ( GLenum target, GLenum mode ) ;
FUNCTION: void glHint GLenum target GLenum mode ;
To make a Factor word with a name different from the C function, use
FUNCTION-ALIAS:.
See alsoFUNCTION-ALIAS:Definition