Fork me on GitHub
#interop
<
2020-05-26
>
Crispin03:05:16

Hi there interop experts!

Crispin03:05:35

I'm having problems avoiding interop when calling a hava constructor.

Crispin03:05:43

here is my code presently:

Crispin03:05:54

(IntPointer. ^"[Ljava.lang.Integer;" (into-array Integer [(int 3)]))

Crispin03:05:04

and its trying to invoke this constructor:

Crispin03:05:42

and running it gives:

Crispin03:05:49

No matching ctor found for class org.bytedeco.javacpp.IntPointer

Crispin03:05:03

and decompiling my generated class file results in:

Crispin03:05:39

final IntPointer intPointer = (IntPointer)Reflector.invokeConstructor(RT.classForName("org.bytedeco.javacpp.IntPointer"), new Object[] { ((IFn)core$_main.const__2.getRawRoot()).invoke(core$_main.const__3, (Object)Tuple.create((Object)RT.intCast(3L))) });

seancorfield03:05:42

It's looking for a native int array, you're passing an array of Integer objects.

Crispin03:05:05

oooh. int is not Integer?! really... :thinking_face:

seancorfield03:05:13

You want (int-array [3])

seancorfield03:05:25

int is Primitive. Integer is a boxed object.

Crispin03:05:36

ok that works

Crispin03:05:49

ok almost there... another one I don't understand

Crispin03:05:09

(.exec ^org.bytedeco.qt.Qt5Widgets.QApplication app)

Crispin03:05:01

No matching field found: exec for class org.bytedeco.qt.Qt5Widgets.QApplication

Crispin03:05:08

decompiled:

Crispin03:05:46

final Object o2 = app;
        app = null;
        Object result = Reflector.invokeNoArgInstanceMember(o2, "exec", false);

Crispin03:05:25

top of traceback:

Crispin03:05:28

:trace
  [[clojure.lang.Reflector getInstanceField "Reflector.java" 397]
   [clojure.lang.Reflector
    invokeNoArgInstanceMember
    "Reflector.java"
    440]
   [decloj.core$_main invokeStatic "core.clj" 26]
   [decloj.core$_main doInvoke "core.clj" 10]

seancorfield03:05:13

Because it's static, not an instance method.

seancorfield03:05:59

(org.bytedeco.qt.Qt5Widgets.QApplication/exec) should call it

Crispin03:05:11

and pass in the app?

seancorfield03:05:52

No, it's a static method with no arguments according to the declaration (although I'm not sure what native does in Java).

Crispin03:05:06

ok thats what threw me

seancorfield03:05:16

app is not involved in the call.

Crispin03:05:17

its calling underlying cpp

seancorfield03:05:33

Yeah, JNI stuff...?

Crispin03:05:34

ok, makes sense. that would be Qt's mainloop

Crispin04:05:53

Ok. all working now

Crispin04:05:24

Qt GUI app in clojure using cpp bindings

Crispin04:05:01

now I'm gonna try graal native-imaging it...