A few days ago, Edward (@ekr) showed how he runs Rust programs from Leo:
It's possible to run Javascript programs from a Leo node, too. First, get GraalJS, which is available for all the major OSs. See
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.