Fork me on GitHub
#clojure
<
2023-07-14
>
mx200014:07:19

Has anyone tried or is there a library to generate wrappers for Java libraries like this https://github.com/henryw374/cljc.java-time/blob/master/dev/gen.clj I am thinking of creating something like this, where you can create full wrappers

Alex Miller (Clojure team)16:07:46

Someone did this a few years ago

Alex Miller (Clojure team)16:07:21

But you might find that a lot of this is soon made obsolete by the method thunk work we’re doing in Clojure 1.12

👀 2
‼️ 2
Alex Miller (Clojure team)16:07:48

https://github.com/clojure-interop/java-jdk and others in that org are what I’m thinking of, but I don’t think they ever released the generator

mx200019:07:42

So does it still make sense to write a generator ? But it is not much code and already working with 70 LOC, the tortilla library is doing most of the work already.

mx200019:07:13

The generator would be very useful to see also. I will try to get in contact. https://github.com/potapenko wrote it?

mx200014:07:20

For every package/class by specifing a package.

mx200014:07:36

I want to make something similar for libgdx what was done here for java-time and maybe it can be a lib which can create wrapper-libs

henryw37415:07:19

yes. https://github.com/emlyn/tortilla not used it directly, but I borrowed some code from it to improve the gen step of cljc.java-time

mx200015:07:53

Yes I know about tortilla and want to use it as a dependency. Why is there a defwrapper in clj-time , is there any difference to tortilla ?

mpenet15:07:36

but I am not a fan of the approach (in general)

mpenet15:07:05

you end up with some twisted apis that are not very "idiomatic" to clj (for lack of a better term)

mpenet15:07:32

at this point going plain interop is just easier (you find more examples/docs etc)

henryw37415:07:57

yes there are some differences ... to make the output bb compatible I think it was. probably not an issue any more

mx200015:07:14

What is bb? I am not sure which code I should get to know more, clj-time.defwrapper or defwrapper lib

henryw37415:07:35

babashka. definitely tortilla. I remembered some more changes I made are to deal with quirks in the js version of java.time that the cljs version of the generated code uses.

henryw37415:07:57

like instead of getX, some fns in the js lib are just called x . ugly stuff. so yeah, tortilla is meant to be general purpose

mx200015:07:59

Thanks very much! Just discovered cljc.java.time yesterday and really appreciate to get a reply from the author immediately

mx200015:07:26

Stayed up the whole night and generated 50,000 lines of wrapper code for libgdx with 70 lines of code

henryw37415:07:33

haha cheers!

mx200015:07:21

I think clojure wrapper libraries are complecting the type hinting/method to function creation and the individual library design. There should be a base wrapper which takes care of the 'plumbing' parts for a Java library and then other wrappers with different design phiolospies on top of it.

mx200015:07:23

So basically what java-time does. I wonder if there can be a standardised way to wrap Java libraries , would make it more simpler to interop

mx200015:07:33

At least low level usage I mean

mx200015:07:36

I was thinking to call it 'tortilla maker'

mx200015:07:58

Or tortilla factory

mx200015:07:53

Tortilla Factory sounds better

lukasz16:07:38

Abstract Tortilla Factory Singleton

❤️ 8
Samuel Ludwig16:07:12

maybe "coffee-mug" or "thermos", since its an easier way to consume Java 😄?

yes 2
mx200016:07:15

I think I want to keep tortilla in the name because it's the main dependency and it makes clear it's about 'wrapping'. Also I can put a tortilla emoji on the GitHub page 🌯

lukasz16:07:41

I mean, tortilla wrap is just right here for the taking

mx200016:07:01

Yeah! tortilla-wrap!

mx200016:07:53

a thin, flat pancake made from maize flour, eaten hot or cold, typically with a savoury filling.

mx200016:07:05

Perfect definition

mx200016:07:08

Hmm, tortilla is just the bread right

mx200016:07:14

Burrito with dependency tortilla, also nice

seancorfield17:07:25

@U0ALH6R89 As a note for future discussions, can you please use threads for follow-up comments after your initial post so there aren't multiple posts in the main channel. Threads produce less "noise" for the thousands of other members here and also make sure there's a single, coherent place for responses rather than them being scattered across multiple messages or threads. Thanks.

2
Eugen18:07:48

can I have a protocol method without arguments? How would I call the method? Right now I have:

(defprotocol SecretsProvider
  (provider-name [] "xx")
  (run [context] "XX"))
with this:
(defrecord VaultSecretsProvider []
  providers/SecretsProvider
  (run [context] [])
  (provider-name [] ::vault))
but I don't know how to call the provider-name functionality (babashka complains that I call it with an argument when it expects 0)

hiredman18:07:04

a protocol function takes at least 1 argument always

borkdude18:07:05

The first argument should always be the object on which you call the protocol method

Jan18:07:23

The 'this' argument is there atleast

Eugen18:07:06

ok. thanks. this is not very obvious from the docs https://clojure.org/reference/protocols . I found this reference now that I was looking for it: > The implementing fn can presume first argument is instanceof AType

dpsutton18:07:16

that seems like a valid criticism. I think you should mention that on http://ask.clojure.org

Eugen18:07:27

wdyt @U064X3EF3 ? ( sorry, I don't know anyone else from clojure team )

dpsutton18:07:10

i suggested on http://ask.clojure.org because it’ll be in his queue and you’ll get a thoughtful answer when he has time