clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2021-05-16T14:22:36.016400Z

i’m trying to use some javascript game libraries from clojurescript. i have a simple shadow-cljs project, and an npm install of https://www.pixijs.com/, and I’ve successfully been able use it to draw sprites. now i’m trying to use https://github.com/alvaromontoro/gamecontroller.js, but when i require that library it’s namespace is empty. how do i debug this issue?

p-himik 2021-05-16T14:46:56.017200Z

Shadow-cljs documentation has a table on how to convert JS requires into CLJS requires. Have you tried other ways of requiring the second library?

2021-05-16T15:38:11.017400Z

this is where my javascript knowledge shows gaps. i’m looking at https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages , and i’ve tried a require as both ["gamecontroller.js" :as gcjs] and ["gamecontroller.js" :refer (gameControl)], but gcjs is an empty map in the first case, and gameControl is undefined in the second case.

2021-05-16T15:38:44.017600Z

or do i have to do something with the https://shadow-cljs.github.io/docs/UsersGuide.html#js-provider ?

p-himik 2021-05-16T15:39:10.017800Z

> but gcjs is an empty map in the first case This seems very wrong. Open up gamecontroller.js and see how it actually exports things.

p-himik 2021-05-16T15:40:30.018Z

If the contents of this file here https://github.com/alvaromontoro/gamecontroller.js/blob/master/dist/gamecontroller.js are the same as what you have locally, then I think the author of the library didn't export it correctly.

p-himik 2021-05-16T15:42:51.018300Z

Same with the minified version - it just modifies window instead of exporting stuff. You can try to access it in your code as (.-gameControl js/window) after you require that library. But it's still not great.

2021-05-16T15:43:00.018500Z

yeah, that’s the one.

2021-05-16T15:45:58.018700Z

awesome.. that worked. and i see that now—the gameControl.init() adds event handlers to window and doesn’t actually create anything.

2021-05-16T15:46:03.018900Z

thanks for your help @p-himik

👍 1