Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for how to use ocall. #29

Open
LeifAndersen opened this issue Jul 13, 2021 · 3 comments
Open

Add docs for how to use ocall. #29

LeifAndersen opened this issue Jul 13, 2021 · 3 comments

Comments

@LeifAndersen
Copy link

Right now there doesn't seem to be any docs on how to use ocall...and I can't seem to figure it out by trial and error myself.

I'm trying to translate:

(.call (oget % "getDoc") %) to use ocall, with no success. I've tried things such as:

(ocall % "getDoc"), (ocall % "getDoc" %), (ocall % ("getDoc")), (ocall "getDoc" %), etc.

I would imagine the first one is what I should be using. But since there's no documentation I can't tell if its breaking because I'm using it wrong, or because of some other error.

@LeifAndersen
Copy link
Author

(In the case of this specific bug, it seems to be expanding to a dynamic call to cljs.core.js_fn_QMARK_, which is undefined. (Which I guess makes sense as js-fn?is a macro and not a function.)

@nicolaus1990
Copy link

Hello @LeifAndersen,

I had the same problem with the js-fn? macro. But this is unrelated to your oops library issue. The problem is that [[https://cljs.github.io/api/cljs.core/js-fnQMARK][js-fn?]] (used in some namespace in oops) requires Clojurescript 1.10.844 and above. And you are most probably using an older clourescript version.

Concerning the usage for ocall, for me the following worked:
#+begin_src clojure
(ocall!+ (get-js-obj) "ellipse" x y w h)
;; Where "ellipse" is the function name of a js object, and arguments x, y, w,
;; and h are integers, in this particular case. Note, however, for some arguments,
;; like sequences, I had to use function clj->js to make it work.
#+end_src

If that doesn't help: The above example came from a proof of concept I wrote using the p5.js library (former processing.js graphics library). I managed to make it work with figwheel-main (for hot-reloading) and even make advance
compilation work for a small example (thanks to oops library). You could check that out [[https://gitlab.com/nicolaus1990/cljs-examples/-/tree/master/p5_examples/p5-example-2][here]], if you think that might help.

@LeifAndersen
Copy link
Author

... requires Clojurescript 1.10.844 and above. And you are most probably using an older clourescript version.

At the time of opening this issue, I was running: 1.10.872 (I have since upgraded to 1.10.932).

Concerning the usage for ocall, for me the following worked:

I'll try it out, thanks for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants