]> gitweb.factorcode.org Git - factor.git/commitdiff
Create a setter for C-GLOBAL words
authorErik Charlebois <erikcharlebois@gmail.com>
Sun, 22 May 2011 07:37:56 +0000 (03:37 -0400)
committerErik Charlebois <erikcharlebois@gmail.com>
Tue, 24 May 2011 03:36:14 +0000 (23:36 -0400)
basis/alien/parser/parser.factor
basis/alien/syntax/syntax-docs.factor

index 32caee214ffd69a252cd978c3c2e845f6ae2b824..6d0cbb79cc7f23d099939e500f3b5fcc638fcfa1 100755 (executable)
@@ -179,5 +179,16 @@ PREDICATE: alien-callback-type-word < typedef-word
     swap [ name>> current-library get ] dip
     '[ _ _ address-of 0 _ alien-value ] ;
 
-: define-global ( type word -- )
+: set-global-quot ( type word -- quot )
+    swap [ name>> current-library get ] dip
+    '[ _ _ address-of 0 _ set-alien-value ] ;
+
+: define-global-getter ( type word -- )
     [ nip ] [ global-quot ] 2bi (( -- value )) define-declared ;
+
+: define-global-setter ( type word -- )
+    [ nip name>> "set-" prepend create-in ]
+    [ set-global-quot ] 2bi (( obj -- )) define-declared ;
+
+: define-global ( type word -- )
+    [ define-global-getter ] [ define-global-setter ] 2bi ;
index 8f60e7e0886688eb43b057fee7b3f1acf5ee9a4f..4901651ce3c4b5ad7c503defe274522b6993652c 100644 (file)
@@ -122,7 +122,7 @@ HELP: typedef
 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: } "." } ;
+{ $description "Defines a getter " { $snippet "name" } " and setter " { $snippet "set-name" } " for the global value in the current library, set with " { $link POSTPONE: LIBRARY: } "." } ;
 
 ARTICLE: "alien.enums" "Enumeration types"
 "The " { $vocab-link "alien.enums" } " vocab contains the implementation for " { $link POSTPONE: ENUM: } " C types, and provides words for converting between enum singletons and integers. It is possible to dispatch off of members of an enum."