interop 2020-05-26

@retrogradeorbit has joined the channel

Hi there interop experts!

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

here is my code presently:

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

and its trying to invoke this constructor:

and running it gives:

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

and decompiling my generated class file results in:

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))) });

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

oooh. int is not Integer?! really... 🤔

You want (int-array [3])

int is Primitive. Integer is a boxed object.

ok that works

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

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

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

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

top of traceback:

: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]

Because it's static, not an instance method.

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

and pass in the app?

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

ok thats what threw me

app is not involved in the call.

its calling underlying cpp

Yeah, JNI stuff...?

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

Ok. all working now

Qt GUI app in clojure using cpp bindings

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

@borkdude has joined the channel