Skip to content
sergeych edited this page Jan 20, 2015 · 8 revisions

The Javascript/Ruby Hybrid engine

Please, keep eye on [ruby docs] (http://www.rubydoc.info/gems/h8/toplevel) - we'll try to keep them actual and informative. In the wiki we only add information that does not fir source docs format and concept.

As you might know, the v8 Javascript engine is roughly 5 to 8 times faster than ruby. Using the Hybrid8 you can take the best from Ruby with the speed of Coffeescript (or Javascript) by having full access from one language to the other in any combinations with correct object wrapping and exception passing.

I mean, you can call javascript code from ruby, passing ruby callbacks/classes to it. Then javascript can call ruby code from within, and pass, in turn, javascript callbacks and functions to ruby code, that can cope with javascript objects at full strength and almost without difference from ruby objects. It even cam raise exception, that will be converted to javascript exception, and if not caught and processed, with be raised back in ruby code. The same, javascript can produce exceptions that could be rescued in ruby caller, and so on.

For the sake of execution speed, h8 gem converts primitive types between languages where possible and worth doing (for example, it won't convert hashes and arrays by default). It is thread safe! If you want to access H8 objects from concurrent thread, do it, but deadlocks/race conditions is up to you to care about. It is recommended though to have different H8::Context and its objects in different threads though, in which case javascripts could execute truly in parallel. Well, when they access ruby objects, yes, they are synchronised to the ruby's gvl, but all the rest can run on different cores at once.

More information is available in rubydocs: http://www.rubydoc.info/gems/h8/toplevel

Clone this wiki locally