Opal - Ruby to Javascript compiler
opalrb.org
Opal - Ruby to Javascript compiler
1–10 of 54 posts
Re: Opal - Ruby to Javascript compiler
#2Re: Opal - Ruby to Javascript compiler
#3 (function() {
var __opal = Opal, self = __opal.top, __scope = __opal, nil = __opal.nil, __breaker = __opal.breaker, __slice = __opal.slice, __klass = __opal.klass;
var adam = nil, __a, __b;
(__b = [1, 2, 3, 4], __b.$each._p = (__a = function(a) {
if (a == null) a = nil;
return this.$puts(a)
}, __a._s = self, __a), __b.$each());
(function(__base, __super){
// line 5, (file), class Foo
function Foo() {};
Foo = __klass(__base, __super, "Foo", Foo);
var Foo_prototype = Foo.prototype, __scope = Foo._scope;
return Foo_prototype.$name = function() {
if (this.name == null) this.name = nil;
return this.name
},
Foo_prototype['$name='] = function(val) {
return this.name = val
}, nil
})(self, null);
adam = __scope.Foo.$new();
adam['$name=']("Adam Beynon");
return self.$puts(adam.$name());
})();Re: Opal - Ruby to Javascript compiler
#4Re: Opal - Ruby to Javascript compiler
#5What the use case for something like this? Am I missing something?
Re: Opal - Ruby to Javascript compiler
#6Yup, that's some good brainfuck: (function() { var __opal = Opal, self = __opal.top, __scope = __opal, nil = __opal.nil, __breaker = __opal.breaker, __slice = __opal.slice, __klass = __opal.klass; var adam = nil, __a, __b; (__b = [1, 2, 3, 4], __b.$each._p = (__a = function(a) { if (a == null) a = nil; return this.$puts(a) }, __a._s = self, __a), __b.$each()); (function(__base, __super){ // line 5, (file), class Foo…
module Run
def run
puts "I am running!"
end
end
module Jump
def jump
puts "I am jumping!"
end
end
class Foo
include Run
include Jump
end
mario = Foo.new
mario.run
mario.jump
translates to: (function() {
var __opal = Opal, self = __opal.top, __scope = __opal, nil = __opal.nil, __breaker = __opal.breaker, __slice = __opal.slice, __module = __opal.module, __klass = __opal.klass;
// Define Mario
var mario = nil;
// Javascript "Run" class
(function(__base){
// line 2, (file), module Run
function Run() {};
Run = __module(__base, "Run", Run);
var Run_prototype = Run.prototype, __scope = Run._scope;
Run_prototype.$run = function() {
return this.$puts("I am running!");
}
;Run._donate(["$run"]);
})(self);
// Javascript "Jump" class
(function(__base){
// line 8, (file), module Jump
function Jump() {};
Jump = __module(__base, "Jump", Jump);
var Jump_prototype = Jump.prototype, __scope = Jump._scope;
Jump_prototype.$jump = function() {
return this.$puts("I am jumping!");
}
;Jump._donate(["$jump"]);
})(self);
// JavaScript "Foo" class
(function(__base, __super){
// line 14, (file), class Foo
function Foo() {};
Foo = __klass(__base, __super, "Foo", Foo);
var Foo_prototype = Foo.prototype, __scope = Foo._scope;
// $include Run / Jump
Foo.$include(__scope.Run);
return Foo.$include(__scope.Jump);
})(self, null);
// The ruby executing code translation
mario = __scope.Foo.$new();
mario.$run();
return mario.$jump();
})();Re: Opal - Ruby to Javascript compiler
#7https://github.com/whitequark/coldruby
http://www.ntecs.de/blog/articles/2007/01/08/rubyjs-javascri...
https://github.com/jessesielaff/red
http://www.playmycode.com/docs/quby
https://github.com/mattknox/8ball
Unfortunately, none of them seem to be to handle the mor dynamic features of ruby, like method_missing, which diminishes the possibility of reusing existing ruby code in the browser.
Re: Opal - Ruby to Javascript compiler
#8What the use case for something like this? Am I missing something?
Porting existing code without having to re-implement. Keeping a single reference implementation of a particular method.
Re: Opal - Ruby to Javascript compiler
#9What the use case for something like this? Am I missing something?
Re: Opal - Ruby to Javascript compiler
#10I'm working on a little programming language myself that compiles to Javascript. In most languages that do this, I wish there was better information on the mapping between the domain language and its Javascript codomain. I think this would be a good open source project idea: a tool to assist in the compilation of various languages to Javascript. Something to the effect of how source lines in C can be printed above their generated assembly. Anyone want to give it a shot?