chickadee » jni

jni

Author

bevuta IT GmbH (Patrick Brauer)

Requirements

Description

JNI Bindings for Chicken Scheme. For more information check: Java Native Interface Specification

API

java-vm parameter
jni-env parameter

jvm-init

(jvm-init [CLASS-PATH "."]) syntax

Initialize jni when chicken is expected to launch the jvm.

jni-init

(jni-init) syntax

Initialize jni when the jvm launchs chicken.

jvm-get-default-init-args

(jvm-get-default-init-args JVM-INIT-ARGS) procedure

Get default init args for the jvm.

jvm-create

(jvm-create JAVA-VM JNI-ENV JVM-INIT-ARGS) procedure

Creates a jvm.

jvm-destroy

(jvm-destroy JAVA-VM) procedure

Destroy a jvm.

jvm-env

(jvm-env JAVA-VM JNI-ENV) procedure

Set output argument JNI-ENV to the current jvm env.

jvm-attach-current-thread

(jvm-attach-current-thread JAVA-VM JNI-ENV) procedure

Attaches the current thread to a Java VM. Returns a JNI interface pointer.

jvm-detach-current-thread

(jvm-detach-current-thread JAVA-VM) procedure

Detaches the current thread from a Java VM. All Java monitors held by this thread are released. All Java threads waiting for this thread to die are notified. Returns JNI\_OK on success; returns a suitable JNI error code (a negative number) on failure.

jimport

(jimport CLASS-NAME [(IMPORT ...)]) syntax

Defines a module with the content of the class and use the import specifiers to import it. The content of the class contains: class methods and fields and a special procedure called "new" to invoke the constructor. The import specifier syntax is the same as the normal import macro. To avoid repeating the module name, you can use <> as a placeholder.

   (jimport java.lang.String)
   (valueOf 1)
   
   (jimport java.lang.String (prefix (only <> valueOf) String-))
   (String-valueOf 1)
   (String-new)

jlambda

(jlambda CLASS [METHOD/FIELD]) syntax
  • (jlambda CLASS) => jclass
  • (jlambda CLASS field) => jlambda-field
  • (jlambda CLASS method) => jlambda-methods
  • (jlambda CLASS new) => jlambda-methods

jlambda-constant

(jlambda-constant TYPE CLASS FIELD) => lambda syntax

Returns a static java constant getter procedure. This macro doesn't requiere a jni-env available until getter invokation. Also, the result is cached so the value is retrieved from java just once.

   (define FLOAT_MAX_VALUE (jlambda-constant float java.lang.Float MAX_VALUE))

jlambda-field

(jlambda-field MODIFIERS TYPE CLASS FIELD) syntax
   (let ((user-lastname (jlambda-field () java.lang.String com.testapp.User lastname))) 
     (print (user-lastname user))
     (set! (user-lastname user) "Perez"))

jlambda-method

(jlambda-method MODIFIERS RETURN-TYPE CLASS METHOD-NAME ARGS...) -> lambda syntax

Returns a lambda associated to the java method. Modifiers could by a list of modifiers or #f

   (jlambda-method #f boolean java.lang.String contains java.lang.CharSequence)

jlambda-methods

(jlambda-methods CLASS-NAME METHOD-NAME ((MODIFIER RETURN-TYPE (ARGS..)) ...)) -> lambda procedure

This procedure will create jlambda-method variants for each signature. When the procedure is invoked will try to resolve the overloaded methods as java will do. If there is not enough information for that, type hints information should be added to help the identification.

   (let ((ov1 (jlambda-methods 'com.chicken_mobile.jni.test.Bar 'bar
                        '((#f int . (int)) 
                          (#f int . (short))
                          (#f int . (java.lang.String))))))
   (ov1 bar 1 "hola")
   (ov1 bar 2 )
   (ov1 bar (type: short 1)))

jlambda-constructor

(jlambda-constructor CLASS ARGS...) -> lambda syntax

Returns a lambda associated to the class constructor.

   (jlambda-constructor java.lang.Integer int))

import-java-ns

(import-java-ns ((PACKAGE-FROM IMPORT) ...)) syntax

IMPORT could be:

  • a class
  • a list of classes
  • * (all)
   (import-java-ns ((java.lang *)
                    (java.lang (System String))
                    (com.bevuta.testapp Foo)))
	(class String)
	(class System)
	(class Foo))

class

(class CLASS-SYMBOL) -> jclass syntax

Returns the associated jclass. Raise error if the class is not found.

   (class java.lang.String)

super-class

(super-class JCLASS) -> jclass procedure

Returns the jclass corresponding to the argument super class.

get-object-class

(get-object-class JOBJECT) -> jclass procedure

Returns the jclass corresponding to the argument object.

instance-of?

(instance-of? JOBJECT JCLASS) procedure

Check if the object is instance of the class.

same-object?

(same-object? JOBJECT JOBJECT) procedure

Check if two objects are the same one.

assignable-from?

(assignable-from? JCLASS JCLASS) procedure

Check if a class is assignable from another.

define-method

(define-method (METHOD_NAME THIS) RETURN-TYPE BODY..) syntax

Implements a native declared method.

   (define-method (com.bevuta.androidChickenTest.Backend.main backend) void
      ...)

References

(new-local-ref JOBJECT) procedure
(delete-local-ref JOBJECT) procedure
(new-global-ref JOBJECT) procedure
(delete-global-ref JOBJECT) procedure

Exceptions

Java exceptions are mapped to conditions of the kind '(exn java exception-class)

java-exception-message

(java-exception-message JAVA-CONDITION) procedure

Get java exception message as string.

java-exception-trace

(java-exception-trace JAVA-CONDITION) procedure

Get java exception trace as string.

java-exception-type

(java-exception-type JAVA-CONDITION) -> EXCEPTION-CLASS-SYMBOL procedure

Get java exception class as symbol.

Other

monitor-enter
(monitor-enter jobject) procedure

Enters the monitor associated with the underlying Java object referred to by obj argument.

monitor-exit
(monitor-exit jobject) procedure

Exit the monitor associated with the underlying Java object referred to by obj argument.

License

BSD License

Version history

Contents »