VS Code ❤ Scilab
Firstly, we need to have installed in our computer both Scilab and VS Code.
Download Code Extensions
We need only two extensions for run Scilab inside VS Code:
- Scilab by mammothb
- Code Runner by Jun Han
Scilab Extension
This extension is useful to make a highlight of the reserved word of Scilab syntaxis, this allow us to have our own customization in VS Code.
This is an example of the two sights of the Scilab in Code vs Scilab IDE:
Code Runner
This extension allow us run code snippets or code files for multiple languages and create custom commands.
Customize Code Runner for Scilab
In this step we need to customize the settings.json
file, particulary, for the code-runner.executorMap
. In this case, I created a Github Repo where I explain my VS Code configurations you can access to it and follow the instructions there, anyway, I'll explain how to configurate the file in this post:
- Open
settings.json
. - Add
code-runner.executorMap
command. - Specify run mode instruction.
- Add Scilab instruction to execute.
Open settings.json
This is the file where you can overwrite the default configurations of the editor.
You can access it with Ctrl + ,
and clicking like the image below:
Add code-runner.executorMap
command
If you are used to move and customize VS Code extensions, this step won't be a problem for you, either way I will show you how to do it.
In the settings.json
file you can find a blank file (or not) and how its own name specify, the instructions needs to be in JSON format.
{
"code-runner.executorMap": {},
}
With this line we can begin to give instructions depending on any programming language we need to overwrite.
Specify run mode instruction
Foremostly, we need to understand what is a run mode in Scilab.
Scilab have 3 different ways to run its programs:
-
Wscilex
: runs the standar Scilab. -
Wscilex-cli
: in this mode, Scilab is started as command line with advanced features still available (graphics, export, xcos, scinotes, help browser, ...). -
Scilex
. this mode has two features:- This mode prevents loading the Java Virtual Machine. It starts faster and uses less memory.
- Scilab is started as command line interpreter without any advanced features requiring the JVM: graphics, export, xcos, scinotes, help browser, other java interfaces, the Java module,... are not available.
We only need to be focus on Wscilex-cli
and Scilex
because we are goin to search for the instalation folder of Scilab (in my case, Scilab is installed in D:\Programs\scilab-6.1.0\
so replace for your path).
Add Scilab instruction to execute
If you want to run Scilab and visualize plots, graphs, images, etc, use the following script:
{
"code-runner.executorMap": {
// run Scilab with graphic Functions
"scilab": "cd $dir && D:\\Programs\\scilab-6.1.0\\bin\\WScilex-cli.exe -nb -f $fileName",
},
}
But if you only want numerical results:
{
"code-runner.executorMap": {
// run Scilab from VSCode
"scilab": "cd $dir && D:\\Programs\\scilab-6.1.0\\bin\\Scilex.exe -nb -quit -f $fileName",
},
}
In both cases we have flags that specify different things:
-
-nb
: "no banner": Cancels the display of the Scilab's loading message. -
-quit
: This option forces scilab to always exit after the instruction(s) passed with the -e option, or the script referred to by the -f option, have been executed, even in case of a runtime error. This option should always be used in batch mode. -
-f file
: This option execute the file which is specified.
For $dir
and $fileName
, these are options nativately used in code-runner configuration.
And that is everything you need to begin with Scilab in VS Code!!
Top comments (6)
Ubuntu Linux version: -quit is important in case you want to rerun the *sce file
{
// run Scilab with graphic Functions
"code-runner.executorMap": {
"scilab": "cd $dir && /home/Tools/scilab-2024.0.0/bin/scilab-cli -nb -quit -f $fileName",
},
}
Thank you very much, you really helped me out❤️
Muchas gracias. Una consulta, existe la posibilidad de utilizar input en Code?, ejm
pcp=input ("Introduzca la contrapresion: ")
slds.
lamento mucho la ausencia😅 pero sí, en este caso el compilador que debes de usar y configurar en el vscode es el de
WScilex-cli.exe
ya que tenemos que usar la consola normal de scilab.¡¡¡Saludos!!!
In output result isn't showing. saying [Done] exited with code=3221225781 in 0.078 seconds
Also nothing in terminal too
Hi
Customise code is done but its not working. Do you have time to resolve the issue with mac for XCOS? Are you developer?