From 54015782f3972ea3478959d9169b27e66a223e7c Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 14 Apr 2010 16:14:33 -0700 Subject: [PATCH] document FUNCTION-ALIAS: --- basis/alien/syntax/syntax-docs.factor | 20 ++++++++++++++++---- core/alien/alien-docs.factor | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/basis/alien/syntax/syntax-docs.factor b/basis/alien/syntax/syntax-docs.factor index df20926480..b71d0bd533 100644 --- a/basis/alien/syntax/syntax-docs.factor +++ b/basis/alien/syntax/syntax-docs.factor @@ -26,9 +26,9 @@ HELP: LIBRARY: { $notes "Logical library names are defined with the " { $link add-library } " word." } ; HELP: FUNCTION: -{ $syntax "FUNCTION: return name ( parameters )" } +{ $syntax "FUNCTION: return name ( parameters ) ;" } { $values { "return" "a C return type" } { "name" "a C function name" } { "parameters" "a comma-separated sequence of type/name pairs; " { $snippet "type1 arg1, type2 arg2, ..." } } } -{ $description "Defines a new word " { $snippet "name" } " which calls a C library function with the same name, in the logical library given by the most recent " { $link POSTPONE: LIBRARY: } " declaration." +{ $description "Defines a new word " { $snippet "name" } " which calls the C library function with the same " { $snippet "name" } " in the logical library given by the most recent " { $link POSTPONE: LIBRARY: } " declaration." $nl "The new word must be compiled before being executed." } { $examples @@ -45,11 +45,23 @@ $nl "The answer to the question is 42." } } "Using the " { $link c-string } " type instead of " { $snippet "char*" } " causes the FFI to automatically convert Factor strings to C strings. See " { $link "c-strings" } " for more information on using strings with the FFI." -{ $notes "Note that the parentheses and commas are only syntax sugar and can be omitted; they serve no purpose other than to make the declaration slightly easier to read:" +{ $notes "Note 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:" { $code "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 " { $link POSTPONE: FUNCTION-ALIAS: } "." } ; + +HELP: FUNCTION-ALIAS: +{ $syntax "FUNCTION-ALIAS: factor-name + return c_name ( parameters ) ;" } +{ $values { "factor-name" "a Factor word name" } { "return" "a C return type" } { "name" "a C function name" } { "parameters" "a comma-separated sequence of type/name pairs; " { $snippet "type1 arg1, type2 arg2, ..." } } } +{ $description "Defines a new word " { $snippet "factor-name" } " which calls the C library function named " { $snippet "c_name" } " in the logical library given by the most recent " { $link POSTPONE: LIBRARY: } " declaration." +$nl +"The new word must be compiled before being executed." } +{ $notes "Note 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." } ; + +{ POSTPONE: FUNCTION: POSTPONE: FUNCTION-ALIAS: } related-words HELP: TYPEDEF: { $syntax "TYPEDEF: old new" } diff --git a/core/alien/alien-docs.factor b/core/alien/alien-docs.factor index 96eb9002be..178e8a6f71 100644 --- a/core/alien/alien-docs.factor +++ b/core/alien/alien-docs.factor @@ -213,6 +213,7 @@ ARTICLE: "alien-invoke" "Calling C from Factor" { $subsections POSTPONE: LIBRARY: POSTPONE: FUNCTION: + POSTPONE: FUNCTION-ALIAS: } "The above parsing words create word definitions which call a lower-level word; you can use it directly, too:" { $subsections alien-invoke }