These are chat archives for opal/opal

16th
Apr 2018
francesco agati
@francescoagati
Apr 16 2018 11:16
hello
how can i use opal inside node for compile a string that contain opal code in javascript?
Guillaume Grossetie
@Mogztter
Apr 16 2018 12:34
Hello @francescoagati you mean a string that contains Ruby code ?
Torsten Rüger
@rubydesign
Apr 16 2018 17:20
@elia First time i'm taking opal-rails for a ride, great work! But there is a small issue (opal balks at safe operator .&) which it doesn't im my opal-sprockets version. Is there a way to control that? Or is is due to the ruby-version that it emulates, and that can be set ?
Elia Schito
@elia
Apr 16 2018 17:20
hmmm, @rubydesign what's the opal version?
can you also post a snippet of the code that's causing the problem?
Torsten Rüger
@rubydesign
Apr 16 2018 17:21
latest
@body&.normalize
Elia Schito
@elia
Apr 16 2018 17:23
⤑ opal -cEO -e '@body&.normalize'                                              ~
/* Generated by Opal 0.11.0 */
(function(Opal) {
  var $a, self = Opal.top, $nesting = [], nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice, $send = Opal.send;
  if (self.body == null) self.body = nil;

  Opal.add_stubs(['$normalize']);
  return ($a = self.body, ($a === nil || $a == null) ? nil : $send($a, 'normalize', []))
})(Opal);
seems to be working fine here, what error are you receiving?
Torsten Rüger
@rubydesign
Apr 16 2018 17:25
@elia yes, like i said, in a opal-sprockets version the code worked for me. So i don't think it is opal itself, rather the opal-rails
Elia Schito
@elia
Apr 16 2018 17:25
sorry I mean, can you paste the actual error with backtrace?
Torsten Rüger
@rubydesign
Apr 16 2018 17:26

SyntaxError (An error occurred while compiling: vool/statements/class_statement

parse error on value "." (tDOT) :vool/statements/class_statement:11
Source: vool/statements/class_statement:11:59
ClassStatement.new(@name , @super_class_name, @body&.normalize )
~~~~~~~~~~~~~~^):

Ilya Bylich
@iliabylich
Apr 16 2018 17:31
ruby-parse -e 'ClassStatement.new(@name , @super_class_name, @body&.normalize )'
(send
  (const nil :ClassStatement) :new
  (ivar :@name)
  (ivar :@super_class_name)
  (csend
    (ivar :@body) :normalize))
Which version of Opal do you use?
The code in the master branch can parse it
Elia Schito
@elia
Apr 16 2018 17:32
@rubydesign try with cat Gemfile.lock | grep opal for a quick check, or bundle show opal
Torsten Rüger
@rubydesign
Apr 16 2018 17:33
uups. 10.5
Elia Schito
@elia
Apr 16 2018 17:33
that's good news, everything's fine :smile:
Torsten Rüger
@rubydesign
Apr 16 2018 17:34
sorry. I assumed. So the latest opal-rails does not use 0.11?
because with opal-sprockets and 0.11 it works
Elia Schito
@elia
Apr 16 2018 17:36
I think it was blocked by opal-jquery which was blocked by opal-rspec, lots of deps :sweat_smile:
I'll check its status anyway
Torsten Rüger
@rubydesign
Apr 16 2018 17:38
i don't use jquery or rspec, do you think i can fork it?
Elia Schito
@elia
Apr 16 2018 17:40
@rubydesign https://rubygems.org/gems/opal-rails try adding gem 'opal', '~> 0.11.0' to your gemfile, there's probably some dependency that's preventing you from loading the latest version
Torsten Rüger
@rubydesign
Apr 16 2018 17:43
Your intuition was right (i had also tried bundle update opal)
opal-rails (= 0.9.4) was resolved to 0.9.4, which depends on
opal-jquery (~> 0.4.0) was resolved to 0.4.0, which depends on
opal (< 0.9.0, >= 0.7.0)
Elia Schito
@elia
Apr 16 2018 17:44
ok, try adding gem 'opal-jquery', github: 'opal/opal-jquery'
should be enough
Torsten Rüger
@rubydesign
Apr 16 2018 17:47
cool, it bundles
Thanks a lot @elia
Elia Schito
@elia
Apr 16 2018 17:51
anytime! :wink:
Torsten Rüger
@rubydesign
Apr 16 2018 17:51
Does give me a buzz seeing 10k lines of ruby run in the browser
Elia Schito
@elia
Apr 16 2018 17:51
:rocket:
Jan Biedermann
@janbiedermann
Apr 16 2018 21:10
Is there a wy to make complex js objects with lots of properties and function to behave like a opal ruby object and also make it known to opal?
Usually one would wrap such object with Native or so, but thats not what i want, i want something like Opal.create_ruby_from_js(js_object, RubyClass) ?
Provided that a RubyClass is declared somewhere.
Or, another way, can i blend a js object in to a ruby object, so that the ruby object behaves like the js object too with its callable functions/properties?
meh.
@meh
Apr 16 2018 21:13
@janbiedermann you probably want to include Native
or not, who knows
Jan Biedermann
@janbiedermann
Apr 16 2018 21:13
no, i dont want that, i want a object that behaves in both worlds, without having to call to_n
(of course, the ruby methods would do the necessary transformations)
Or, put another way, what does a js object need to be recognized and callable from opal? How can i add ruby methods to a js object?
G. Gibson
@mistergibson
Apr 16 2018 21:16
Could you have a @native_object and do method_missing / send combo on it?
Jan Biedermann
@janbiedermann
Apr 16 2018 21:18
priority is this object to be callable from js, so then i want to attach ruby methods to that js object, so its callable from ruby.
Like
js_object['$ruby_method'] = function my_ruby_thing_here() { bla bla }
but thats obviously not enough, is it?
thats Native upside down i guess
Jan Biedermann
@janbiedermann
Apr 16 2018 21:23
or maybe to be more clear:
given js_object has native function "do_whatever"
i want:
js_object['$do_whatever'] = function () {
   this.do_whatever();
}
so i can pass this js_object around in opal and do
js_object.do_whatever
so i can add this to the prototype of the js thing, so all js things of this kind are callable from opal and no need to the wrapping all the time.
Jan Biedermann
@janbiedermann
Apr 16 2018 21:29
Oh, right, that true for Array, right? in a way. so i just look how opal treats Array and do the same for my js thing, maybe?
so what does that exactly do?
class Array < `Array`
Jan Biedermann
@janbiedermann
Apr 16 2018 21:34
thats just it, isnt it?