Skip to content

Instantly share code, notes, and snippets.

@postspectacular
Created April 30, 2016 22:24
Show Gist options
  • Save postspectacular/d0d86076e1f9e1f3864a836b73b55556 to your computer and use it in GitHub Desktop.
Save postspectacular/d0d86076e1f9e1f3864a836b73b55556 to your computer and use it in GitHub Desktop.
Wrapping & calling compiled C fns from Clojurescript
;; initialize particle system and
;; create C function wrappers
(let [psys (.ccall js/Particles "initParticleSystem" "*"
#js ["number" "number" "number" "number"]
#js [10000 1000 0.0 -0.01 0.125])
psys-update (.cwrap js/Particles "updateParticleSystem" "*"
#js ["number"])
psys-count (.cwrap js/Particles "getNumParticles" "number"
#js ["number"])
particle-ptr (.ccall js/Particles "getParticlesPointer" "*"
#js ["number"] #js [psys])]
;; store in app state atom for future use
(swap! app merge
{:psys psys
:psys-update psys-update
:psys-count psys-count
:psys-get psys-get
:particle-ptr particle-ptr}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment