OPA how to reuse Javascript and Node.js packages -


so read article of 12 jan 2012 on how include existing javascript packages plugin in opa: http://blog.opalang.org/2012/01/reusing-javascript-libraries-jquery-ui.html

however in announcement opa 1.1.0 states on feb 12 2013:

"with opa 1.1.0, can include javascript code , node.js packages easier ever! write soon."

so inlcude node.js packages (an sdk), questions new easy method of doing this?

before had prepare special file js values exported opa tagged special annotations like:

##register value_name : type_of_arg1, type_of_arg2 -> void ##args(arg1, arg2) {   run_somejs_code(); } 

the file had compiled package special tool , usable in opa %%filename.value_name%%(x,y).

now tagging of js values opa types , marking them export opa inside js source files in comment syntax /** */. files still valid js files, can update existing js files in place. not require special tool compile them. standard opa compiler accept js files other opa file , understands annotations in comments. before, link client js , server node.js code same way.

unfortunately, of advanced opa feature poorly documented , have read standard library sources learn it. basic functionality available this:

bslleaflet.js:

// these native js "types" available in opa /** @externtype leaflet_map */ /**  * @register {string, float, float, int, bool, bool -> leaflet_map}  */ function leafletmap(id, center_lat, center_lon, zoom, zoomcontrol, attributioncontrol) {   return l.map(id, {center:[center_lat, center_lon], zoom:zoom, zoomcontrol:zoomcontrol, attributioncontrol:attributioncontrol}); } 

mymap.opa:

type leaflet_map = external leaflet_map map = %%bslleaflet.leafletmap%%("my_map_id", lat, lon, 14, true, true) 

although doing simple things easy , quick, learn things like:

  • running js function continuations,
  • using opa types in js (can use custom opa records?),
  • using arguments of list type (is translation opa's {hd,tl} or {nil} js list performed automatically opa bool={true} or {false} js boolean?),
  • running opa functions passed arguments js functions,

requires experimenting. if manage understand of it, write because glad learn :)


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -