Changes between Version 9 and Version 10 of JavaFfi


Ignore:
Timestamp:
11/25/10 22:46:42 (13 years ago)
Author:
astalla
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • JavaFfi

    v9 v10  
    7878(jstatic "getRuntime" (jclass "java.lang.Runtime")) => #<java.lang.Runtime java.lang.Runtime@1ef3212 {C8E4DE}>
    7979(jstatic (jmethod "java.lang.Runtime" "getRuntime") nil) => #<java.lang.Runtime java.lang.Runtime@1ef3212 {129DF8A}>
     80}}}
     81
     82=== Function JFIELD, JFIELD-RAW, (SETF JFIELD) ===
     83
     84'''Syntax:'''
     85
     86'''jfield''' ''class-ref-or-field field-or-instance &optional instance value => object''
     87
     88'''jfield-raw''' ''class-ref-or-field field-or-instance &optional instance value => JAVA-OBJECT''
     89
     90(setf ('''jfield''' ''class-ref-or-field field-or-instance &optional (instance nil instance-supplied-p) unused-value'') ''newvalue'')
     91
     92'''Arguments and Values:'''
     93
     94`class-ref-or-field` -- depending on the usage pattern, a Java class designator or a string naming a field in a Java object.
     95
     96`field-or-instance` -- depending on the usage pattern, a Java object or a string naming a field in a Java object.
     97
     98`instance` -- a Java object.
     99
     100`value` -- an object; the new value of the field.
     101
     102`unused-value` -- ignored, present only to make `(setf jfield)` accept the same parameter patterns as `jfield`.
     103
     104'''Description:'''
     105
     106`jfield` is a complex operator supporting several usage patterns for reading the value of a Java field. For historical reasons, `jfield` can also be used to set the value of a field, but the more idiomatic form `(setf jfield)` should be preferred. These are the possible usages of `jfield`:
     107
     108For reading values:
     109 1. `(jfield `''class-ref field''`)`: Retrieves the value of the static field `field` from class `class-ref`.
     110 2. `(jfield `''field instance''`)`: Retrieves the value of the field `field` from the Java object `instance`. The class to which the field belongs is taken to be the class of `instance`.
     111 3. `(jfield `''class-ref field instance''`)`: Retrieves the value of the field `field` of the class `class-ref` from the Java object `instance`.
     112
     113For storing values:
     114 4. `(jfield `''class-ref field primitive-value''`)`: Stores `primitive-value` as the value of the static field `field` of class `class-ref`.
     115 5. `(jfield `''field instance value''`)`: Stores `value` as the value of the field `field` in the Java object `instance`. The class to which the field belongs is taken to be the class of `instance`.
     116 6. `(jfield `''class-ref field instance value''`)`: Stores `value` as the value of the field `field` of the class `class-ref` in the Java object `instance`.
     117 7. `(jfield `''class-ref field''` NIL `''value''`)`: Stores `value` as the value of the static field `field` of class `class-ref`, when `value` could be confused with an instance (case 3).
     118
     119`(setf jfield)` can be used with patterns 1, 2 and 3 to store a value where `jfield` would have read it from.
     120
     121`jfield` translates the value of the field to a Lisp object when possible. `jfield-raw` performs no such translation.
     122
     123'''Examples:'''
     124
     125{{{
     126(jfield "java.lang.System" "out") => #<java.io.PrintStream java.io.PrintStream@198a1f4 {1B0D990}>
     127(jfield "width" (jnew "java.awt.Dimension")) => 0
     128
     129(let ((d (jnew "java.awt.Dimension")))
     130  (setf (jfield "width" d) 42)
     131  (jcall "toString" d))
     132
     133=> "java.awt.Dimension[width=42,height=0]"
    80134}}}
    81135