execute-external-file & execute-general-script

30 views
Skip to first unread message

Félix

unread,
Jun 9, 2024, 3:56:45 PMJun 9
to leo-editor
Hello Leonistas! :)

I'm currently implementing and testing the execute-external-file & execute-general-script commands in LeoJS.

execute-external-file was made by Thomas around February 2023 while execute-general-script was made by Edward around june 2021.

I was just wondering if anyone could send me 'minimal/proof-of-concept' stripped down leo file(s) to test any of those two commands. (with simple 'toy'/'hello-world' scripts to run with them) If you have a few minutes to spare to prepare such a thing... :)

Thanks! 

Félix

Thomas Passin

unread,
Jun 9, 2024, 4:26:16 PMJun 9
to leo-editor
For the execute-external-file script, here is one of my test files,  a tiny Julia file (of course, install Julia first):

headline: @file julia-1.jl
# function to calculate the volume of a sphere
function sphere_vol(r)
    # julia allows Unicode names (in UTF-8 encoding)
    # so either "pi" or the symbol π can be used
    # return (4/3)*pi*r^3
    return (4/3)*π*r^3
end

vol = sphere_vol(3)

# @printf allows number formatting but does not automatically append the \n to statements
using Printf
@printf "volume = %0.3f\n" vol


For the command to find the Julia processor, you have to create an @data settings node named @data run-external-processor-map, like this one (.py scripts are hardcoded in, of course, and don't need to be included here):

EXTENSIONS
.jl: julia  # Trailing comments are allowed
.lua: lua
.rb: ruby
.nim: nim

PROCESSORS
julia: julia
lua: lua
nim: nim
# Originally, ruby was not on the PATH, so we needed its full path:
# ruby: C:\Ruby27-x64\bin\ruby.exe

# After ruby was added to the PATH, we could use its bare name:
ruby: ruby


This command is supposed to open a new terminal window and run the command in it.  The terminal *must* stay open after the external program ends so that the user can read any output (especially error messages!).  The trickiest part of the command is figuring out the terminal launch command for Linux that will launch and stay open at the end, since there is no one standard method good on all Linux distros.  My script uses some heuristics to try to get it right.  These can include scanning the --help output of the candidate terminal, IIRC.

Félix

unread,
Jun 9, 2024, 5:39:48 PMJun 9
to leo-editor
Merci Thomas! :)

Thomas Passin

unread,
Jun 9, 2024, 5:48:42 PMJun 9
to leo-editor
Go, Félix!

Félix

unread,
Jun 9, 2024, 10:22:40 PMJun 9
to leo-editor
I got it working with the julia setup you provided! thanks a lot for your example.

I also tried it with a simple shell script like this and it also worked 
example.png

and I also got the 'execute-general-script' command working so I'll release a new LeoJS beta version with all the new stuff and recent fixes in a day or two! 

:)

Thanks again! 

Thomas Passin

unread,
Jun 9, 2024, 11:23:35 PMJun 9
to leo-editor
Good to know, Felix.  Please see if you can test it on one or another Linux distros - I had a hard time getting the script to work with some of them.

I think getting the script to work is an important milestone.  It means that we can develop code with LeoJs in many other languages than javascript/txx

Thomas Passin

unread,
Jun 10, 2024, 1:12:31 PMJun 10
to leo-editor
I don't have an example for execute-general-script, but I want to point out that it is not the same command as CTRL-B, execute-script.
Reply all
Reply to author
Forward
0 new messages