简体   繁体   中英

Clojure - java interop - How to pass a float array>

I need to call a java function from clojure, which takes a float array as a parameter. How would I do this in clojure?

I tried

(classname/function [0.1f 0.2f]) - but this doesn't work. Clearly the issue is with the parameter array. I can call other functions in the class with no problems, provide they don't take an array as a parameter.

Any suggestions?

Thank you

it looks like that function wants an array of GLfloats so the build in shortcut of float-array may not give you what you need. the general array builder function is (into-array type aseq)

so it may look something like:

(def my-array (into-array GLfloat [0.0 0.0 0.0]))

into array is longer winded though more general.

Try float-array . From the documetation:

user=> (doc float-array)
-------------------------
clojure.core/float-array
([size-or-seq] [size init-val-or-seq])
  Creates an array of floats
nil
user=> (float-array [1 2 3])
#<float[] [F@e1666>
user=> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM