Bridge Crystal to Javascript with crjsc.

228 views
Skip to first unread message

Brandon McGinty-Carroll

unread,
Jan 27, 2017, 3:19:00 AM1/27/17
to crysta...@googlegroups.com
I figured maybe someone on the list here might find this interesting, though crystalshards should pick it up.
http://github.com/bmmcginty/crjsc
links Crystal with the JavaScriptCore library used by WebKit (Safari) to connect Crystal and Javascript.
You can write code that accesses Crystal classes and functions, and that code can call out to Javascript as well.
The functions on the crystal side do have to be written in a certain way, unpacking a single array of arguments, but everything else should be pretty transparent.

If anyone finds a use(s) for this, I'd love to hear about it.
I'm going to try and work on a shim to give js access to a node like environment provided by Crystal.
That way, existing npm packages can be run and accessed from Crystal.
Thanks to @bcardiff and the creator of duktape.cr (Jesse Doyle) for inspirations and pointers to code, and to everyone on the IRC channel and this list for assistance and ideas.
Crystal and it's community are awesome.
(As a side note, I know the language has hooked me permanently. I've started trying to type crystal while working on python projects.)

Thanks,
Brandon McGinty-Carroll

Martin Verzilli

unread,
Jan 27, 2017, 7:54:32 AM1/27/17
to Crystal
Hi Brandon! The project looks super cool, and your words about Crystal and the community <3.

Do you have any example use case? I'm not familiar with JavaScriptCore. 

I apologize in advance if these are stupid questions: What would be the environment where JavaScript interacts with Crystal? Would it for example simplify the job of writing an Electron desktop app backend in Crystal?

Thank you and congrats on the project!

Brandon McGinty-Carroll

unread,
Jan 27, 2017, 2:44:52 PM1/27/17
to crysta...@googlegroups.com
JavaScriptCore is just a Javascript interpreter.
My first goal is to be able to drive the Zombi web-browsing npm package with crystal.
I'll be able to access javascript-heavy webpages and access their contents from within Crystal.
Electron looks awesome, but sadly, I don't think crjsc can really help here. (As a side note, it looks like you can spawn a subprocess in Electron and have Crystal generate your webpages.)
With this project, you could release anapp that allowed users to write extensions or extra functionality in Javascript.
Or write an app in Javascript and call back into Crystal for the performance critical bits.

Brandon




On Fri, Jan 27, 2017 at 04:54:32AM -0800, Martin Verzilli wrote:
> Hi Brandon! The project looks super cool, and your words about Crystal and the community <3.
> Do you have any example use case? I'm not familiar with JavaScriptCore.
>
>
> I apologize in advance if these are stupid questions: What would be the environment where JavaScript interacts with Crystal? Would it for example simplify the job of writing an Electron desktop app backend in Crystal?
>
> Thank you and congrats on the project!
>
>
> On Friday, January 27, 2017 at 5:19:00 AM UTC-3, Brandon McGinty-Carroll wrote:> I figured maybe someone on the list here might find this interesting, though crystalshards should pick it up.
> >
>
>
>
>
> [crystal-lang...@googlegroups.com](http://go.bmcginty.us/26379)
>
>
> [crysta...@googlegroups.com](http://go.bmcginty.us/26377)
>
>
> [google.com-group-crystal-lang](http://go.bmcginty.us/26375)
>
>
> [google.com-d-msgid-crystal-lang-5cc3e330-39f1-4205-936a-ec0c](http://go.bmcginty.us/26376)
>
>
> [google.com-d-optout](http://go.bmcginty.us/26374)
>
>

Roger Pack

unread,
Jan 29, 2017, 12:41:01 AM1/29/17
to Crystal
Unrelated, but I did note that recently rust made it so they can target asm.js
Perhaps someday Crystal can follow suit, I'd love to be able to manipulate the DOM with crystal LOL.
-roger-
Reply all
Reply to author
Forward
0 new messages