These are chat archives for opal/opal

6th
May 2015
Forrest Chang
@fkchang
May 06 2015 00:25
@elia @adambeynon got closer, seems to work, but global variables cause this Extension server error: Inspector protocol error: Object has too long reference chain(must not be longer than 1000)

Not exactly sure why, I apparently can call the object

$dm.class.name # works

but trying to call the just the variable, causes that error

$dm # generates the exception

I pray @adambeynon or anyone might have a clue. So close, but so far

Elia Schito
@elia
May 06 2015 00:34
Have you googled the error already ?
Forrest Chang
@fkchang
May 06 2015 00:44
@elia seems like this might be it in general https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/T1IqBsNr1-U where it looks like I'd have to munge what the opal compiler gives
Elia Schito
@elia
May 06 2015 00:52
I think it can serialize with json the name which is a string and not the obj itself for obvious reasons
Forrest Chang
@fkchang
May 06 2015 01:10
Yeah, so the question is can we make opal objects json stringifyable? or do I munge the compiled output to force to_s or someting? @adambeynon ?
otherwise fairly close to a chrome panel that you can have opal-irb in any opal app w/o having to build it in
this unfortunately the last evaluated object, because everything has to be stringified?
Forrest Chang
@fkchang
May 06 2015 01:41
So it seems when it comes back, it loses the opal prototype
unless @adambeynon or anyone else has any ideas, I think I'm going to give up on the chrome panel
Adam Beynon
@adambeynon
May 06 2015 06:24
@fkchang iirc, when I looked at it before, my plan of action was to inject the compiler/parser into the page itself, and the REPL was just a case of passing the string to the page context, doing the compiling there, and then returning the result
if you want to do object inspection, then all that logic and code etc would need to live in the page itself, and the extension just asks for the json representation
its all very awkward, but unfortunately thats the way it is
opal-parser.js could have all that logic baked in
so the chrome extension is just an interface to that logic
Forrest Chang
@fkchang
May 06 2015 14:11
@adambeynon what I believe is happening is that the chrome panel runs as it's own process, thus allowing it to have different js libs and what not. javascript chrome.devtools.inspectedWindow.eval runs it in the context of the inspected window and the result gets json-stringify-ed to be sent back to the chrome panel. If I understand your example, you want to inject the compiler into the page, and use javascript inspectedWIndow.eval to communicate w/that one? Hmm, I might be able to make that work, but it is convoluted. After killing a day yesterday, I think I'll let that digest a bit
Though maybe just improving opal-irb and other tools so they have less dependencies and is easier to insert into ones app (mostly it's the dependencies that make that a little harder) might be better ROI
@adambeynon did u have an idea of how u would inject the parser into the page?
Forrest Chang
@fkchang
May 06 2015 14:32
I suppose I could precompile the pertinent classes into a single js file and inject that. The problem I see w/that is that may or may not run if there is an opal version conflict, whereas the chrome panel way of doing it simply sends code across to be evaled in the inspected window's context w/o injecting possibly incompatible code. Not sure if it would be worth the time
Elia Schito
@elia
May 06 2015 14:34
I kinda like the irb solution more (as a safari user :P)
Vais Salikhov
@vais
May 06 2015 14:39

Guys, can someone please tell me how in the world this works:

$ bundle exec opal-repl
>> puts "hool\u0007"
hoola
=> nil
>> puts "hool\u001b"
hoole
=> nil

It's been driving me crazy for a couple of days already that I can't figure it out. @adambeynon any pointers where this transformation occurs in the parse/compile process?

Elia Schito
@elia
May 06 2015 14:44
@vais check the lexer too
> opal --sexp -Oe 'puts "hool\u0007"'
(:call, nil, :puts, (:arglist, (:str, "hool\a")))
@vais probably def read_escape
Vais Salikhov
@vais
May 06 2015 15:08
@elia thanks, but this is exactly the place that's been driving me crazy - read_escape seems to be doing the right thing, but somehow, somewhere down the line this transformation occurs. read_escape definitely does not convert \u0007 into a and \u001b into e... wtf..
Elia Schito
@elia
May 06 2015 15:10
@vais that means it's after lexing and before parsing as the sexp already shows \a
Vais Salikhov
@vais
May 06 2015 15:11
Something is converting these unicode escapes into \a and \e which are not recognized by javascript, it just sees them as literal a and e. How to make them stay as unicode escapes all the way into js-land?
Elia Schito
@elia
May 06 2015 15:11
drop a puts :bomb:
but beware escaping: inspect vs. to_s
Vais Salikhov
@vais
May 06 2015 15:23
@elia I dropped so many puts bombs the whole thing looks like the surface of the moon :sweat:
Giving up for today. @elia if you or @adambeynon can take a look, plz lmk... It's not super urgent, just hate the feeling.
Elia Schito
@elia
May 06 2015 15:26
lol :)
quick attempt shows it's the lexer
>> l = Opal::Lexer.new('"\u0007"', 'file')
=> #<Opal::Lexer:0x007feb78c7e028 @lex_state=:expr_beg, @cond=0, @cmdarg=0, @line=1, @tok_line=1, @column=0, @tok_column=0, @file="file", @scanner=#<StringScanner 0/8 @ "\"\\u00...">, @scanner_stack=[#<StringScanner 0/8 @ "\"\\u00...">], @case_stmt=nil, @start_of_lambda=nil>
>> l.next_token
=> [:tSTRING_BEG, ["\"", [1, 0]]]
>> l.next_token
=> [:tSTRING_CONTENT, ["\a", [1, 1]]]
>> l.next_token
=> [:tSTRING_END, ["\"", [1, 7]]]
>>
but also in ruby:
>> "\u0007"
=> "\a"
scanner[1].to_i(16).chr(Encoding::UTF_8)
converts to a hex num and then picks the corresponding char
Vais Salikhov
@vais
May 06 2015 15:31
@elia right, so then "\a" goes into js-land
But there it no longer has the same meaning
Ok, it's late here, my brain is fried. Thanks for the pointer, @elia, I'll pick it up tomorrow. :zzz:
Elia Schito
@elia
May 06 2015 15:36
:+1:
Mitch VanDuyn
@catmando
May 06 2015 20:29
anybody: using opal-rspec and playing with react.rb... this needs to include react.js... not sure how to add a include to the opal-rspec header that seems like its generated automatically by opal-rspec. Can anybody explain how I would go about including a js file so its there for all the specs to run?
Forrest Chang
@fkchang
May 06 2015 20:59
@catmando if react.js is in the load path you can just do a require 'react'
Mitch VanDuyn
@catmando
May 06 2015 21:04
problem is I am using gem react.rb which is also called "react"
So I guess I need to pull down react.js save it in assets, rename it to something like react-js.js and then require 'react-js' will that work?
Forrest Chang
@fkchang
May 06 2015 21:27
@catmando there will be a problem if 2 files are compiled to react.js, maybe you can have a path that uniquely identifies it say, require 'vendor/assets/javascripts/react/react' or if you include an html file as your html for the test, you could do a script tag there
Mitch VanDuyn
@catmando
May 06 2015 21:35
@fkchang.. I guess. In this case its really a matter of new library (react.rb) that needs to under the hood include react.js... For now I took the route I suggested (rename react.js to react_js.js) and that works fine.
@fkchang - please explain "or if you include an html file as your html for the test, you could do a script tag there" That was my original approach, but I could not figure out how to get opal-rspec to use a different index file.
Elia Schito
@elia
May 06 2015 21:45
@catmando @fkchang react.rb depends on react-source which is the gem from facebook itself
not sure with which path you can require it tho
Mitch VanDuyn
@catmando
May 06 2015 21:48
@elia, yeah I also could not figure that out... There is no doc for react-source. Also react.rb only requires react-source in development (!?)
Elia Schito
@elia
May 06 2015 21:48
and it doesn't work out of the box uh…
Mitch VanDuyn
@catmando
May 06 2015 21:50
I am guessing react-source would be required using 'react' but the name conflicts. I guess I could try renaming react.rb so that you can require react_rb or some such...
Elia Schito
@elia
May 06 2015 21:51
my gut tells me @zetachang has done his work properly and you don't need to
Mitch VanDuyn
@catmando
May 06 2015 21:52
could be, I am going to put in an issue, and perhaps he can clarify everything
Forrest Chang
@fkchang
May 06 2015 21:58
@catmando when you config the rake task for your opal specs you can configure the index file i.e. ruby Opal::RSpec::RakeTask.new("spec:opal") do |s| s.index_path = "opal/spec/index.html"
This message was deleted
Mitch VanDuyn
@catmando
May 06 2015 22:04
@fkchang... gotcha... thanks...
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 22:47
How should I handle data loading at compile time?
Elia Schito
@elia
May 06 2015 22:56
@krainboltgreene what do you mean?
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 22:57
@elia: I'm making a game, and I have configuration data stored as json files.
I want to load those files as native Ruby objects and have those available in runtime.
Elia Schito
@elia
May 06 2015 22:58
Like hashes or something else?
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:02
@elia: Sure.
Elia Schito
@elia
May 06 2015 23:02
you can either require 'json'
or require 'native' and do Hash.new(`{a: 1}`)
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:03
That doesn't get the data from the files.
meh.
@meh
May 06 2015 23:04
krainboltgreene, just put the json in a .js and into a global variable, then require the .js and Hash.new(`global`)
that's the simplest way
Forrest Chang
@fkchang
May 06 2015 23:05
@krainboltgreene you want to load it at page load time? How r u serving up stuff? opal-rails for example lets you expand controller variables in your views, so in rails I'll use that a lot
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:05
Haha what.
@fkchang I want to load it at compile time.
It seems like the Dir library has SOME methods meant for compile time.
It just doesn't have Dir#glob()
Forrest Chang
@fkchang
May 06 2015 23:06
@krainboltgreene not sure if this is exactly what you want to do, but I'vbe got something like this
meh.
@meh
May 06 2015 23:07
krainboltgreene, we don't really have a file system available
Forrest Chang
@fkchang
May 06 2015 23:07

:opal
  Document.ready? do
    $mi = MapInterface.new(#{@json}, #{ZipCoords.zipcode_hash})
  end
where @json is set in the controller, and ZipCoords.zipcode_hash is a bunch of zipcode shape data stored in server side objects
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:08
Argh, File.read doesn't exist either.
meh.
@meh
May 06 2015 23:08
krainboltgreene, we just cannot have it
Elia Schito
@elia
May 06 2015 23:08
@krainboltgreene the only place where we have a file system is node.js, in the browser File.read doesn't make sense
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:08
I know that.
Elia Schito
@elia
May 06 2015 23:08
you in a browser?
meh.
@meh
May 06 2015 23:09
krainboltgreene, if you want it at compile time, you do as I said, you put the json in a .js file with global = <JSON>
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:09
Yes, but like I'd like to do file stuff as it's getting compiled.
meh.
@meh
May 06 2015 23:09
then you require it, and you have it available in global
Forrest Chang
@fkchang
May 06 2015 23:09
@krainboltgreene I would imagine that you would have something similar in a game, to the scheme that I have for the map example I gave you.
Elia Schito
@elia
May 06 2015 23:10
@krainboltgreene listen to @meh :) require is the right way
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:16
It seems weird that I have the ability to require files but not get the contents of files.
I know why, I understand why, but :?
Elia Schito
@elia
May 06 2015 23:17
how so?
meh.
@meh
May 06 2015 23:17
krainboltgreene, even require doesn't do what you think it does
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:17
Would it be so terrible to assume all Dir, File, and Path domains refered to a "fake" filesystem loaded by Opal.environment?
I know what it does meh, I've looked at the source.
meh.
@meh
May 06 2015 23:17
krainboltgreene, it wouldn't work out well with how dynamic Ruby is
we can't just assume a constant is the top level one
and we can't assume it's not been overloaded
we'd need compiler macros
but it's a lot of work for not much good
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:18
I don't see why you would.
Just implement filesystem operations as if they were talking to an Opal.environment virtual fs.
meh.
@meh
May 06 2015 23:21
that would be doable assuming you tell the compiler which files to embed
but even then you'd have to assume all the files are text, since strings are UTF-16 in js
so it would just be a halfassed implementation
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:22
@meh: We already tell the compilier which directory to pay attention to.
BTW, I love what Opal::Builder has done in my rakefile.
Much easier to read.
meh.
@meh
May 06 2015 23:29
krainboltgreene, have you considered using END?
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:31
@meh: What's that?
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:32
Oh shit right.
meh.
@meh
May 06 2015 23:32
that's supported
Kurtis Rainbolt-Greene
@krainboltgreene
May 06 2015 23:46
That might be OK for small things, but this dataset could get large. I think what I'll do is be "fancy" and add "data" to my path, use Kernal#load() and use Ruby native datastructs instead of JSON.