alien.syntax: add C-GLOBAL: for defining words to access global variables, and remove the gimpy one from core-text.utilities
parent
18d4f030cd
commit
b88fde04d9
|
@ -45,10 +45,12 @@ HELP: load-library
|
||||||
|
|
||||||
HELP: add-library
|
HELP: add-library
|
||||||
{ $values { "name" string } { "path" string } { "abi" "one of " { $snippet "\"cdecl\"" } " or " { $snippet "\"stdcall\"" } } }
|
{ $values { "name" string } { "path" string } { "abi" "one of " { $snippet "\"cdecl\"" } " or " { $snippet "\"stdcall\"" } } }
|
||||||
{ $description "Defines a new logical library named " { $snippet "name" } " located in the file system at " { $snippet "path" } "and the specified ABI." }
|
{ $description "Defines a new logical library named " { $snippet "name" } " located in the file system at " { $snippet "path" } " and the specified ABI. The logical library name can then be used by a " { $link POSTPONE: LIBRARY: } " form to specify the logical library for subsequent " { $link POSTPONE: FUNCTION: } " definitions." }
|
||||||
{ $notes "Because the entire source file is parsed before top-level forms are executed, " { $link add-library } " cannot be used in the same file as " { $link POSTPONE: FUNCTION: } " definitions from that library. The " { $link add-library } " call will happen too late, after compilation, and the alien calls will not work."
|
{ $notes "Because the entire source file is parsed before top-level forms are executed, " { $link add-library } " must be placed within a " { $snippet "<< ... >>" } " parse-time evaluation block."
|
||||||
$nl
|
$nl
|
||||||
"Instead, " { $link add-library } " calls must either be placed in different source files from those that use that library, or alternatively, " { $link "syntax-immediate" } " can be used to load the library before compilation." }
|
"This ensures that if the logical library is later used in the same file, for example by a " { $link POSTPONE: FUNCTION: } " definition. Otherwise, the " { $link add-library } " call will happen too late, after compilation, and the C function calls will not refer to the correct library."
|
||||||
|
$nl
|
||||||
|
"For details about parse-time evaluation, see " { $link "syntax-immediate" } "." }
|
||||||
{ $examples "Here is a typical usage of " { $link add-library } ":"
|
{ $examples "Here is a typical usage of " { $link add-library } ":"
|
||||||
{ $code
|
{ $code
|
||||||
"<< \"freetype\" {"
|
"<< \"freetype\" {"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
IN: alien.syntax
|
IN: alien.syntax
|
||||||
USING: alien alien.c-types alien.parser classes.struct help.markup help.syntax see ;
|
USING: alien alien.c-types alien.parser alien.libraries
|
||||||
|
classes.struct help.markup help.syntax see ;
|
||||||
|
|
||||||
HELP: DLL"
|
HELP: DLL"
|
||||||
{ $syntax "DLL\" path\"" }
|
{ $syntax "DLL\" path\"" }
|
||||||
|
@ -21,7 +22,8 @@ ARTICLE: "syntax-aliens" "Alien object literal syntax"
|
||||||
HELP: LIBRARY:
|
HELP: LIBRARY:
|
||||||
{ $syntax "LIBRARY: name" }
|
{ $syntax "LIBRARY: name" }
|
||||||
{ $values { "name" "a logical library name" } }
|
{ $values { "name" "a logical library name" } }
|
||||||
{ $description "Sets the logical library for consequent " { $link POSTPONE: FUNCTION: } " definitions that follow." } ;
|
{ $description "Sets the logical library for consequent " { $link POSTPONE: FUNCTION: } ", " { $link POSTPONE: C-GLOBAL: } " and " { $link POSTPONE: CALLBACK: } " definitions, as well as " { $link POSTPONE: &: } " forms." }
|
||||||
|
{ $notes "Logical library names are defined with the " { $link add-library } " word." } ;
|
||||||
|
|
||||||
HELP: FUNCTION:
|
HELP: FUNCTION:
|
||||||
{ $syntax "FUNCTION: return name ( parameters )" }
|
{ $syntax "FUNCTION: return name ( parameters )" }
|
||||||
|
@ -96,21 +98,26 @@ HELP: CALLBACK:
|
||||||
|
|
||||||
HELP: &:
|
HELP: &:
|
||||||
{ $syntax "&: symbol" }
|
{ $syntax "&: symbol" }
|
||||||
{ $values { "symbol" "A C library symbol name" } }
|
{ $values { "symbol" "A C global variable name" } }
|
||||||
{ $description "Pushes the address of a symbol named " { $snippet "symbol" } " from the current library, set with " { $link POSTPONE: LIBRARY: } "." } ;
|
{ $description "Pushes the address of a symbol named " { $snippet "symbol" } " from the current library, set with " { $link POSTPONE: LIBRARY: } "." } ;
|
||||||
|
|
||||||
HELP: typedef
|
HELP: typedef
|
||||||
{ $values { "old" "a string" } { "new" "a string" } }
|
{ $values { "old" "a C type" } { "new" "a C type" } }
|
||||||
{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } "." }
|
{ $description "Aliases the C type " { $snippet "old" } " under the name " { $snippet "new" } "." }
|
||||||
{ $notes "Using this word in the same source file which defines C bindings can cause problems, because words are compiled before top-level forms are run. Use the " { $link POSTPONE: TYPEDEF: } " word instead." } ;
|
{ $notes "Using this word in the same source file which defines C bindings can cause problems, because words are compiled before top-level forms are run. Use the " { $link POSTPONE: TYPEDEF: } " word instead." } ;
|
||||||
|
|
||||||
{ POSTPONE: TYPEDEF: typedef } related-words
|
{ POSTPONE: TYPEDEF: typedef } related-words
|
||||||
|
|
||||||
HELP: c-struct?
|
HELP: c-struct?
|
||||||
{ $values { "c-type" "a C type name" } { "?" "a boolean" } }
|
{ $values { "c-type" "a C type" } { "?" "a boolean" } }
|
||||||
{ $description "Tests if a C type is a structure defined by " { $link POSTPONE: STRUCT: } "." } ;
|
{ $description "Tests if a C type is a structure defined by " { $link POSTPONE: STRUCT: } "." } ;
|
||||||
|
|
||||||
HELP: define-function
|
HELP: define-function
|
||||||
{ $values { "return" "a C return type" } { "library" "a logical library name" } { "function" "a C function name" } { "parameters" "a sequence of C parameter types" } }
|
{ $values { "return" "a C return type" } { "library" "a logical library name" } { "function" "a C function name" } { "parameters" "a sequence of C parameter types" } }
|
||||||
{ $description "Defines a word named " { $snippet "function" } " in the current vocabulary (see " { $link "vocabularies" } "). The word calls " { $link alien-invoke } " with the specified parameters." }
|
{ $description "Defines a word named " { $snippet "function" } " in the current vocabulary (see " { $link "vocabularies" } "). The word calls " { $link alien-invoke } " with the specified parameters." }
|
||||||
{ $notes "This word is used to implement the " { $link POSTPONE: FUNCTION: } " parsing word." } ;
|
{ $notes "This word is used to implement the " { $link POSTPONE: FUNCTION: } " parsing word." } ;
|
||||||
|
|
||||||
|
HELP: C-GLOBAL:
|
||||||
|
{ $syntax "C-GLOBAL: type name" }
|
||||||
|
{ $values { "type" "a C type" } { "name" "a C global variable name" } }
|
||||||
|
{ $description "Defines a new word named " { $snippet "name" } " which accesses a global variable in the current library, set with " { $link POSTPONE: LIBRARY: } "." } ;
|
||||||
|
|
|
@ -38,3 +38,12 @@ ERROR: no-such-symbol name library ;
|
||||||
|
|
||||||
SYNTAX: &:
|
SYNTAX: &:
|
||||||
scan "c-library" get '[ _ _ address-of ] over push-all ;
|
scan "c-library" get '[ _ _ address-of ] over push-all ;
|
||||||
|
|
||||||
|
: global-quot ( type word -- quot )
|
||||||
|
name>> "c-library" get '[ _ _ address-of 0 ]
|
||||||
|
swap c-type-getter-boxer append ;
|
||||||
|
|
||||||
|
: define-global ( type word -- )
|
||||||
|
[ nip ] [ global-quot ] 2bi (( -- value )) define-declared ;
|
||||||
|
|
||||||
|
SYNTAX: C-GLOBAL: scan-c-type CREATE-WORD define-global ;
|
||||||
|
|
|
@ -6,19 +6,19 @@ math.order math.vectors math.rectangles math.functions locals init
|
||||||
namespaces combinators fonts colors cache core-foundation
|
namespaces combinators fonts colors cache core-foundation
|
||||||
core-foundation.strings core-foundation.attributed-strings
|
core-foundation.strings core-foundation.attributed-strings
|
||||||
core-foundation.utilities core-graphics core-graphics.types
|
core-foundation.utilities core-graphics core-graphics.types
|
||||||
core-text.fonts core-text.utilities ;
|
core-text.fonts ;
|
||||||
IN: core-text
|
IN: core-text
|
||||||
|
|
||||||
TYPEDEF: void* CTLineRef
|
TYPEDEF: void* CTLineRef
|
||||||
|
|
||||||
C-GLOBAL: kCTFontAttributeName
|
C-GLOBAL: CFStringRef kCTFontAttributeName
|
||||||
C-GLOBAL: kCTKernAttributeName
|
C-GLOBAL: CFStringRef kCTKernAttributeName
|
||||||
C-GLOBAL: kCTLigatureAttributeName
|
C-GLOBAL: CFStringRef kCTLigatureAttributeName
|
||||||
C-GLOBAL: kCTForegroundColorAttributeName
|
C-GLOBAL: CFStringRef kCTForegroundColorAttributeName
|
||||||
C-GLOBAL: kCTParagraphStyleAttributeName
|
C-GLOBAL: CFStringRef kCTParagraphStyleAttributeName
|
||||||
C-GLOBAL: kCTUnderlineStyleAttributeName
|
C-GLOBAL: CFStringRef kCTUnderlineStyleAttributeName
|
||||||
C-GLOBAL: kCTVerticalFormsAttributeName
|
C-GLOBAL: CFStringRef kCTVerticalFormsAttributeName
|
||||||
C-GLOBAL: kCTGlyphInfoAttributeName
|
C-GLOBAL: CFStringRef kCTGlyphInfoAttributeName
|
||||||
|
|
||||||
FUNCTION: CTLineRef CTLineCreateWithAttributedString ( CFAttributedStringRef string ) ;
|
FUNCTION: CTLineRef CTLineCreateWithAttributedString ( CFAttributedStringRef string ) ;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.c-types alien.syntax assocs core-foundation
|
USING: accessors alien.c-types alien.syntax assocs core-foundation
|
||||||
core-foundation.dictionaries core-foundation.strings
|
core-foundation.dictionaries core-foundation.strings
|
||||||
core-graphics.types core-text.utilities destructors init
|
core-graphics.types destructors init
|
||||||
kernel math memoize fonts combinators unix.types ;
|
kernel math memoize fonts combinators unix.types ;
|
||||||
IN: core-text.fonts
|
IN: core-text.fonts
|
||||||
|
|
||||||
|
@ -18,28 +18,28 @@ TYPEDEF: void* CTFontDescriptorRef
|
||||||
: kCTFontVerticalTrait ( -- n ) 11 2^ ; inline
|
: kCTFontVerticalTrait ( -- n ) 11 2^ ; inline
|
||||||
: kCTFontUIOptimizedTrait ( -- n ) 12 2^ ; inline
|
: kCTFontUIOptimizedTrait ( -- n ) 12 2^ ; inline
|
||||||
|
|
||||||
C-GLOBAL: kCTFontSymbolicTrait
|
C-GLOBAL: CFStringRef kCTFontSymbolicTrait
|
||||||
C-GLOBAL: kCTFontWeightTrait
|
C-GLOBAL: CFStringRef kCTFontWeightTrait
|
||||||
C-GLOBAL: kCTFontWidthTrait
|
C-GLOBAL: CFStringRef kCTFontWidthTrait
|
||||||
C-GLOBAL: kCTFontSlantTrait
|
C-GLOBAL: CFStringRef kCTFontSlantTrait
|
||||||
|
|
||||||
C-GLOBAL: kCTFontNameAttribute
|
C-GLOBAL: CFStringRef kCTFontNameAttribute
|
||||||
C-GLOBAL: kCTFontDisplayNameAttribute
|
C-GLOBAL: CFStringRef kCTFontDisplayNameAttribute
|
||||||
C-GLOBAL: kCTFontFamilyNameAttribute
|
C-GLOBAL: CFStringRef kCTFontFamilyNameAttribute
|
||||||
C-GLOBAL: kCTFontStyleNameAttribute
|
C-GLOBAL: CFStringRef kCTFontStyleNameAttribute
|
||||||
C-GLOBAL: kCTFontTraitsAttribute
|
C-GLOBAL: CFStringRef kCTFontTraitsAttribute
|
||||||
C-GLOBAL: kCTFontVariationAttribute
|
C-GLOBAL: CFStringRef kCTFontVariationAttribute
|
||||||
C-GLOBAL: kCTFontSizeAttribute
|
C-GLOBAL: CFStringRef kCTFontSizeAttribute
|
||||||
C-GLOBAL: kCTFontMatrixAttribute
|
C-GLOBAL: CFStringRef kCTFontMatrixAttribute
|
||||||
C-GLOBAL: kCTFontCascadeListAttribute
|
C-GLOBAL: CFStringRef kCTFontCascadeListAttribute
|
||||||
C-GLOBAL: kCTFontCharacterSetAttribute
|
C-GLOBAL: CFStringRef kCTFontCharacterSetAttribute
|
||||||
C-GLOBAL: kCTFontLanguagesAttribute
|
C-GLOBAL: CFStringRef kCTFontLanguagesAttribute
|
||||||
C-GLOBAL: kCTFontBaselineAdjustAttribute
|
C-GLOBAL: CFStringRef kCTFontBaselineAdjustAttribute
|
||||||
C-GLOBAL: kCTFontMacintoshEncodingsAttribute
|
C-GLOBAL: CFStringRef kCTFontMacintoshEncodingsAttribute
|
||||||
C-GLOBAL: kCTFontFeaturesAttribute
|
C-GLOBAL: CFStringRef kCTFontFeaturesAttribute
|
||||||
C-GLOBAL: kCTFontFeatureSettingsAttribute
|
C-GLOBAL: CFStringRef kCTFontFeatureSettingsAttribute
|
||||||
C-GLOBAL: kCTFontFixedAdvanceAttribute
|
C-GLOBAL: CFStringRef kCTFontFixedAdvanceAttribute
|
||||||
C-GLOBAL: kCTFontOrientationAttribute
|
C-GLOBAL: CFStringRef kCTFontOrientationAttribute
|
||||||
|
|
||||||
FUNCTION: CTFontDescriptorRef CTFontDescriptorCreateWithAttributes (
|
FUNCTION: CTFontDescriptorRef CTFontDescriptorCreateWithAttributes (
|
||||||
CFDictionaryRef attributes
|
CFDictionaryRef attributes
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Slava Pestov
|
|
|
@ -1,10 +0,0 @@
|
||||||
! Copyright (C) 2009 Slava Pestov.
|
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
|
||||||
USING: words parser alien alien.c-types kernel fry accessors
|
|
||||||
alien.libraries ;
|
|
||||||
IN: core-text.utilities
|
|
||||||
|
|
||||||
SYNTAX: C-GLOBAL:
|
|
||||||
CREATE-WORD
|
|
||||||
dup name>> '[ _ f dlsym *void* ]
|
|
||||||
(( -- value )) define-declared ;
|
|
|
@ -192,6 +192,13 @@ ARTICLE: "alien-callback" "Calling Factor from C"
|
||||||
{ $subsections "alien-callback-gc" }
|
{ $subsections "alien-callback-gc" }
|
||||||
{ $see-also "byte-arrays-gc" } ;
|
{ $see-also "byte-arrays-gc" } ;
|
||||||
|
|
||||||
|
ARTICLE: "alien-globals" "Accessing C global variables"
|
||||||
|
"The " { $vocab-link "alien.syntax" } " vocabulary defines two parsing words for accessing the value of a global variable, and get the address of a global variable, respectively."
|
||||||
|
{ $subsections
|
||||||
|
POSTPONE: C-GLOBAL:
|
||||||
|
POSTPONE: &:
|
||||||
|
} ;
|
||||||
|
|
||||||
ARTICLE: "dll.private" "DLL handles"
|
ARTICLE: "dll.private" "DLL handles"
|
||||||
"DLL handles are a built-in class of objects which represent loaded native libraries. DLL handles are instances of the " { $link dll } " class, and have a literal syntax used for debugging prinouts; see " { $link "syntax-aliens" } "."
|
"DLL handles are a built-in class of objects which represent loaded native libraries. DLL handles are instances of the " { $link dll } " class, and have a literal syntax used for debugging prinouts; see " { $link "syntax-aliens" } "."
|
||||||
$nl
|
$nl
|
||||||
|
@ -281,6 +288,7 @@ $nl
|
||||||
"alien-callback"
|
"alien-callback"
|
||||||
"c-data"
|
"c-data"
|
||||||
"classes.struct"
|
"classes.struct"
|
||||||
|
"alien-globals"
|
||||||
"dll.private"
|
"dll.private"
|
||||||
"embedding"
|
"embedding"
|
||||||
} ;
|
} ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien alien.syntax combinators kernel system
|
USING: accessors alien alien.syntax combinators kernel system
|
||||||
alien.libraries classes.struct ;
|
alien.c-types alien.libraries classes.struct unix.types ;
|
||||||
IN: curses.ffi
|
IN: curses.ffi
|
||||||
|
|
||||||
<< "curses" {
|
<< "curses" {
|
||||||
|
@ -74,8 +74,7 @@ STRUCT: c-window
|
||||||
|
|
||||||
LIBRARY: curses
|
LIBRARY: curses
|
||||||
|
|
||||||
: stdscr ( -- alien )
|
C-GLOBAL: void* stdscr
|
||||||
"stdscr" "curses" library dll>> dlsym ;
|
|
||||||
|
|
||||||
FUNCTION: WINDOW* initscr ( ) ;
|
FUNCTION: WINDOW* initscr ( ) ;
|
||||||
FUNCTION: int endwin ( ) ;
|
FUNCTION: int endwin ( ) ;
|
||||||
|
|
Loading…
Reference in New Issue