GraalJS can use classes in jar files, and it even supports nodejs, but I haven't learned how yet.
On Sunday, March 22, 2020 at 2:46:42 PM UTC-4, Thomas Passin wrote: > > A few days ago, Edward (@ekr) showed how he runs Rust programs from Leo: > > https://groups.google.com/forum/#!topic/leo-editor/QBvmeT0zQyM > > It's possible to run Javascript programs from a Leo node, too. First, get > GraalJS, which is available for all the major OSs. See > > https://github.com/graalvm/graaljs > https://github.com/graalvm/graalvm-ce-builds/releases > > Once it's on your machine, find its *languages *directory. In there, you > want the* languages/js/bin/js *executable. On my Windows computer it's at > > D:\usr\graalvm-ce-java11-20.0.0\languages\js\bin\js.exe > > The following Python code will submit to GraalJS the code in the node > selected in the outline, and display anything that was printed to STDOUT. > Of course, adjust the path to the *js* executable. > > from subprocess import run > > graal = r"D:\usr\graalvm-ce-java11-20.0.0\languages\js\bin\js.exe" > raw = p.b > progfile = 'arg1.txt' > > # Remove all lines starting with "@language" > lines = raw.split('\n') > prog = '\n'.join([line for line in lines if not > line.startswith('@language')]) > > with open(progfile, 'w') as f: > f.write(prog) > > cmd = f'{graal} {progfile}' > result = run(cmd, capture_output=True, text=True, encoding='utf-8') > > g.es(result.stdout or 'no output') > > I have this in a @command node, hot keyed to F6. Since GraalJS is built > on a java foundation, you might think it would be slow to load. But not so > - I'm finding it just about instantaneous to run a tiny program. > > Note that this example doesn't capture STDERR, but that's easy enough to > arrange. > > It should be straightforward to adapt for Viewrendered3. > > > > > -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/6fbd5200-4515-4136-b1d2-a1d397c0b0b0%40googlegroups.com.
