These are chat archives for opal/opal

2nd
Jun 2015
Elia Schito
@elia
Jun 02 2015 00:12
hopefully will end up in a PR on their side avoiding usage of rubygems :)
Jeremy Evans
@jeremyevans
Jun 02 2015 00:30
@elia Any chance of the recv.JS.meth stuff making 0.8.0 final? The PR is ready now and all issues have been addressed as far as I know.
Vais Salikhov
@vais
Jun 02 2015 01:10
@elia no objections, it's long overdue IMHO. I mean if someone's like "I'm gonna try this Opal thing out to see what everybody's talking about..." and does gem install opal right now, they'll be getting 0.7.2:scream:
:+1: on @jeremyevans opal/opal#879
CJ Lazell
@cj
Jun 02 2015 01:42
@jeremyevans hey, long time no speak :) Glad to see you getting into Opal! So your pull request would get rid of the need for this code I have? https://github.com/wedgeio/wedge/blob/master/lib/wedge/component.rb#L270-L294
Mitch VanDuyn
@catmando
Jun 02 2015 02:36
does anybody know if class_eval is not fully implemented? Looking at the code it seems not, but there is no caveat in the documentation. Seems it will not work on a string, only if a block is supplied.
Vais Salikhov
@vais
Jun 02 2015 05:24
@catmando that' right, it's not. The reasoning behind this, AFAIK, is that a block can be used without needing the compiler at runtime, but a string would require one.
Mitch VanDuyn
@catmando
Jun 02 2015 12:56
Okay... I'm going to do a PR that will add the capability by requiring the parser. I.e. if parser is loaded then you get the full capability...
Adam Beynon
@adambeynon
Jun 02 2015 13:54
@catmando bare in mind, the compiler can only compile code that gets evaluated in the top/main context. It can’t take an optional context (object or class) to run against
Mitch VanDuyn
@catmando
Jun 02 2015 14:28
so far this seems to work, but only with limited testing :-)
class Module
  alias_method :old_class_eval, :class_eval
  def class_eval(*args, &block)
    #puts "new class eval has block?: #{!!block}"
    if !block
      cstring = "lambda {\n#{args[0]}\n}"
      #puts "building block from #{cstring}"
      #puts "testing Opal #{Opal.compile('puts "hi"')}"
      #puts 
      compiled = Opal.compile(cstring)
      #puts "got some compiled stuff here #{compiled}"
      block = `eval(#{compiled})`
      #puts "got a nice block #{block}"
    end
    #puts "should be good to go #{block}"
    return old_class_eval(&block)
  end
end
Mitch VanDuyn
@catmando
Jun 02 2015 14:37
@adambeynon Should this work okay? Seems like it does...
meh.
@meh
Jun 02 2015 14:38
catmando, yeah, it's not a bad idea
Adam Beynon
@adambeynon
Jun 02 2015 16:13
@catmando yeah, but what Im saying is that any code inside that string will evaluate with ‘main’ as the self context. The class won’t be the value of self
Mitch VanDuyn
@catmando
Jun 02 2015 16:15
@adambeynon I thought wrapping it the lambda and then passing it back to the original class_eval would take care fo setting the context?
Adam Beynon
@adambeynon
Jun 02 2015 16:16
@catmando sorry
yes
you’re right
I missed that part :+1:
Mitch VanDuyn
@catmando
Jun 02 2015 16:27
no drama... the nice thing that i discovered is that if the parser is not present then compile returns nothing. So this method can just raise a nice error explaining that "require 'opal-parser' in order to use string blocks"
Adam Beynon
@adambeynon
Jun 02 2015 16:29
nice, yeap, sounds good to me :+1:
Mitch VanDuyn
@catmando
Jun 02 2015 16:43

hey has anybody seen this problem: Looks like you can't call super from self.included in a module. For example:

module ModuleToInclude

  def self.included(base) 
    puts "about to call super"
    super 
    puts "done with super"
  rescue Exception => e
    puts "whoops #{e}"
  end

end

class TheIncluder

  include ModuleToInclude

end

in MRI you get:

about to call super
done with super
 => TheIncluder

but in Opal you get

about to call super
whoops ReferenceError: $ModuleToInclude is not defined
Mitch VanDuyn
@catmando
Jun 02 2015 17:51
Folks - I'm full of obscure questions today! Is catch symbol do ... end not implemented?
catch :foo do
  puts 'hi'
end
fails with undefined method catch for main!
Mitch VanDuyn
@catmando
Jun 02 2015 18:21
the above is being tested at opalrb.org/try which reports version 0.8.1
Mitch VanDuyn
@catmando
Jun 02 2015 18:31
the test spec is at line 368 of minitest/assertions.rb