Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Mitch VanDuyn
@catmando
pants on backwards stupid... I was looking at the wrong line of code in nodejs.js and thinking it was looking for stdout but it was looking for stderr!
Guillaume Grossetie
@Mogztter
The project is really designed to work on Node.js (not on browser). With Webpack & co it's possible to use a npm package. Basically these tools will automatically stub Node.js native modules like process: https://webpack.js.org/configuration/node/
Jan Biedermann
@janbiedermann

@catmando the es6_modules_1_1 PR#1976 is able to build bundles for node and browser: https://github.com/opal/opal/pull/1976#issuecomment-493799538,
you would need to pull, and in the npm directory are all the goodies:
https://github.com/janbiedermann/opal/tree/es6_modules_1_1/npm

yarn install
yarn run library_build

will build you all the opal files, ready to be imported by webpack or node.

oh, and bundle install in the outer opal directory first.
Jan Biedermann
@janbiedermann

https://addons.mozilla.org/de/firefox/addon/opaldevtools/
Opal Developer Tools - currently a console for using ruby in the browser, recommended with Opal 1.0
Also works with 0.11, but tab completion only works on 1.0

The Chrome Extension install from the WebStore has to wait a bit until i sorted some burocratic things.

However, the extension is easy to build and easy to manually install.
Repo and Instructions here:
https://github.com/isomorfeus/opal-devtools

Mitch VanDuyn
@catmando
@janbiedermann does it support debugging at a breakpoint?
I.e can u see local ruby variables on the stack within a breakpoint?
Jan Biedermann
@janbiedermann
No, that you do in the browser debugger. It does allow you to conveniently execute ruby in the browser.
There is a debuggerin js available, but all it does is show the browser debugger.
Oh!
Just found something!
Jan Biedermann
@janbiedermann
Ok, maybe next version, and only for chrome.
What it could do is something like debug "Hyperstack.some_method", but it will then jump to the browser debugger when this method is called. Maybe its best to just use the browser debugger.
Mitch VanDuyn
@catmando
@janbiedermann yeah I have thought a lot about this, and as far as I can see there is no way easily to implement it. It would require some low level access into the debugger system. The problem is when you hit a break point (debug statement) you stop and go into the chrome debugger, but there is no way (that I know of) to capture the current stack context and pass it to another method. Like the equivilent of the ruby bind method.
On the other hand if you invent your own method like hyperbug then you have the same problem inside that method....
Elia Schito
@elia
Lucas Nicodemus
@hakusaro
@elia yep, found it :)
thank you
Elia Schito
@elia
👍 anytime
Elia Schito
@elia
I think this means for us that we can start transitioning to vanilla JS object for kwargs, which I suspect will greatly simplify things and make calls way faster and readable when compiled! https://blog.saeloun.com/2019/10/07/ruby-2-7-keyword-arguments-redesign.html
Jan Biedermann
@janbiedermann
:+1:
Jan Biedermann
@janbiedermann
Jan Biedermann
@janbiedermann
There is now the Zeitwerk autoloader ported to Opal available: https://github.com/isomorfeus/opal-zeitwerk, as gem too.
Allows for autoloading modules to reduce TTI for large projects or for development comfort because all those require 'bla' can go ...
Currently requires the es6_modules_1_1 branch of Opal, which i updated to the latest master.
Elia Schito
@elia
great stuff :clap:
Jean-Eric Godard
@jeezs
Hello, how can get the content of a proc, using opal-parser (static version)? thanks for help
Guillaume Grossetie
@Mogztter
Hello, I'm using the following code
class Person {
  sayHello(name) {
    return `Hello ${name}`
  }
}
const person = new Person()
console.log(person.sayHello('Guillaume'))
Opal.def(person, '$foo', function () {
  return 'foo'
})
console.log(person.$foo())
console.log(person.sayHello('Guillaume')) // Uncaught TypeError: person.sayHello is not a function
My use case is to provide a JavaScript API where the user can give me an object instantiated from a native JavaScript class
Guillaume Grossetie
@Mogztter
and then I'm trying to mimic Opal to define functions prefixed by $ (most of them will just delegate to the instance)
the issue is that the class functions are "lost"
Jan Biedermann
@janbiedermann
shouldnt it be:
console.log(person.$sayHello('Guillaume'))
?
note the dollar
Guillaume Grossetie
@Mogztter
no because person is not instantiated by Opal
so I also get TypeError: person.$sayHello is not a function
Jan Biedermann
@janbiedermann
Oh, then i suppose def fails, because person is missing some class info.
Guillaume Grossetie
@Mogztter
Here's another example:
// defined by the user
class Converter {
  convert(nodeType) {
    if (nodeType === 'paragraph') {
      return this.convertParagraph() // this.convertParagraph is not a function
    }
    return ''
  }

  convertParagraph() {
    return '<p>paragraph</p>'
  }
}
const converter = new Converter()
console.log(converter.convert('paragraph'))

// add a delegate function
Opal.def(converter, '$convert', converter.convert)

// call by "Opal"
console.log(converter.$convert('paragraph'))
so the user defines a "normal" class, then I add a delegate function because Opal is going to call $convert no convert in my transpiled code
but since converter does not have convertParagraph attached on it anymore
I'm not saying we should support that because it might be a bad usage but I'm not sure how to do it differently
Jan Biedermann
@janbiedermann
You can try upside down, you use a ruby class for converter/person and add js function to it.
So it mimics also the js class.
Guillaume Grossetie
@Mogztter
currently my workaround is to create an empty Object to register the function $convert on it : https://github.com/asciidoctor/asciidoctor.js/pull/766/files#diff-e859cfdd5163b0e3f34ad6ae5b2c4b85R1033-R1038
so Opal do not alter the converter instance
I don't want to do that because I want to "hide" Opal from the "pure" JavaScript API
I don't want the user to use Opal.klass(/*...*/) in the API (if possible)
I believe the Opal.def function expects an Opal.klass instance, so I should probably just recreate an Opal class from the object converter
Jan Biedermann
@janbiedermann
Oh, i see. You may try that, or you go without def and just try converter.$convert = function() ...
Guillaume Grossetie
@Mogztter
true, thanks for your help Jan
Elia Schito
@elia
@Mogztter what about a simple person.$foo = function(){return "foo"}?