These are chat archives for opal/opal

13th
Mar 2018
Simon George
@sfcgeorge
Mar 13 2018 09:08
@elia I guess every Object.new would have to effectively $object_space << self but couldn't work for strings, ints, other primitives without wrapping them. Not really practical. @janbiedermann While JS doesn't have it, it's more of a VM thing than a language thing, so I wonder if V8 has it - aka you could possibly find the V8 API for it, wrap it in an ObjectSpace cloen, then server-render whatever you're doing just for debugging.
Jan Biedermann
@janbiedermann
Mar 13 2018 09:13
@sfcgeorge thats a interesting idea, but i need it in the browsers
dummy
@dummy27680406_twitter
Mar 13 2018 12:37
Hi :) Given I want to write opal library like opal-browser is, what would be place to start? I have no idea how to structure that code or anything... is there any tutorial on that yet?
Elia Schito
@elia
Mar 13 2018 13:17
@dummy27680406_twitter see the guides section on the site http://opalrb.com/docs/guides/v0.11.0/index.html
Jan Hovancik
@hovancik
Mar 13 2018 13:18
does opalrb.org works for you folks?
dummy
@dummy27680406_twitter
Mar 13 2018 13:18
@hovancik nope; and doesn't work for some time now; dunno why
Elia Schito
@elia
Mar 13 2018 13:19
@hovancik nope, the new domain is opalrb.com
Jan Hovancik
@hovancik
Mar 13 2018 13:19
Ah, the logo from docs links to .org
dummy
@dummy27680406_twitter
Mar 13 2018 13:19
yep, lot's of pages still link to .org, wonder why there is no redirect at least or something
Elia Schito
@elia
Mar 13 2018 13:20
@hovancik I'll fix it, thanks for noticing
@dummy27680406_twitter there were some redirects in place through github pages, please let me know if there are any other broken links
dummy
@dummy27680406_twitter
Mar 13 2018 13:21
@elia oh, so... in what I would call "ruby" part I just do Opal.append_part and then just write opal code in that folder?
and that should be enough to get it working?
@elia I know that https://github.com/fazibear/awesome-opal for example points in the wrong way but dunno if there is any affiliation "official" opal
affiliation to "official" opal*
Elia Schito
@elia
Mar 13 2018 13:25
@dummy27680406_twitter yes, Opal.append_path "#{gem_root}/opal" or something like that, looking at opal-jquery code is another good starting point
@dummy27680406_twitter fazibear/awesome-opal#17 thanks
Simon George
@sfcgeorge
Mar 13 2018 13:28

@janbiedermann This "works" by some definition of works. Not for primitives but general objects yes.

$object_space = []

class Object
  def self.new(*args, &block)
    obj = allocate
    obj.send(:initialize, *args, &block)
    $object_space << obj
    obj
  end
end

You get a lot of Opal internal stuff in there, but you can select what you want:

Opal.eval('class Foo; end; Foo.new; puts $object_space.select { |o| o.is_a? Foo }')
dummy
@dummy27680406_twitter
Mar 13 2018 13:28
@elia yeeey opal-jquery looks simple enough to follow, thanks :)
Elia Schito
@elia
Mar 13 2018 14:17
just pushed docs gh-pages, links should update soon
Jamie Gaskins
@jgaskins
Mar 13 2018 15:46
@sfcgeorge Worth noting that that code shouldn't be used in production. It will prevent any Ruby objects (and anything they reference, such as JS objects or DOM nodes/events) from being garbage-collected.
Ideally, if ES6 WeakSet instances were iterable, you'd wanna use that as a container. Or if other object references could be marked as weak, that'd be nice, too.
Simon George
@sfcgeorge
Mar 13 2018 16:18
@jgaskins Very true thanks, I should've specified that. Ooh that's an interesting feature, very Swifty. JS is a big bag of everything, like the new Perl. ES6 at the same time as Perl 6, coincidence? I think not. (I actually quite like Perl 6 though)
Is there any way to get the last error in Opal? aka $!? I don't see globals in the unsupported guide, but I feel like they might be unsupported / it's not working.
Elia Schito
@elia
Mar 13 2018 16:22
@sfcgeorge then it's a bug, $! should work, maybe you uncovered some kind of edge case
Simon George
@sfcgeorge
Mar 13 2018 16:24
@elia Thanks, I tried again and it was the way I was playing in the console
Elia Schito
@elia
Mar 13 2018 16:29
nice to hear :sweat_smile:
Simon George
@sfcgeorge
Mar 13 2018 16:32

@elia Yeah! And apparently I misunderstood what $! does in Ruby. It's not a global storing the last error raised as I thought, it stores the last error not handled. Which is pointless as if you don't handle it your program crashes anyway, and if you do then you can just use the e in rescue => e. AKA I wanted to do this but that's not how Ruby works:

raise "Foo" rescue nil

puts $!.message

An error is happening within a library and I was hoping I could use that global to see what it is without patching the library, but nope.