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-vmparameter
jni-envparameter

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-ARGSprocedure

Get default init args for the jvm.

jvm-create

jvm-create JAVA-VM JNI-ENV JVM-INIT-ARGSprocedure

Creates a jvm.

jvm-destroy

jvm-destroy JAVA-VMprocedure

Destroy a jvm.

jvm-env

jvm-env JAVA-VM JNI-ENVprocedure

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

jvm-attach-current-thread

jvm-attach-current-thread JAVA-VM JNI-ENVprocedure

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

jvm-detach-current-thread

jvm-detach-current-thread JAVA-VMprocedure

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 JCLASSprocedure

Returns the jclass corresponding to the argument super class.

get-object-class

get-object-class JOBJECTprocedure

Returns the jclass corresponding to the argument object.

instance-of?

instance-of? JOBJECT JCLASSprocedure

Check if the object is instance of the class.

same-object?

same-object? JOBJECT JOBJECTprocedure

Check if two objects are the same one.

assignable-from?

assignable-from? JCLASS JCLASSprocedure

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 JOBJECTprocedure
delete-local-ref JOBJECTprocedure
new-global-ref JOBJECTprocedure
delete-global-ref JOBJECTprocedure

Exceptions

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

java-exception-message

java-exception-message JAVA-CONDITIONprocedure

Get java exception message as string.

java-exception-trace

java-exception-trace JAVA-CONDITIONprocedure

Get java exception trace as string.

java-exception-type

java-exception-type JAVA-CONDITIONprocedure

Get java exception class as symbol.

Other

monitor-enter
monitor-enter jobjectprocedure

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

monitor-exit
monitor-exit jobjectprocedure

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

License

BSD License

Version history

Contents »