/ Using jsish


The following describes a few of the ways to use jsish.


Interactive mode is the easiest way to try out code snippets, eg:

# var a = [1,2,3];
# for (var i in a) { puts(a[i]); }


The script file to be executed is the first argument:

jsish prog.js arg1 arg2

Under unix, the first line of executable scripts can be #!:

#!/usr/bin/env jsish
for (var i in console.args)

The above allows jsish to be found in the path.


Javascript can also be evaluated from the command-line with -e, eg:
jsish -e 'var i = 0; while (i++<10) puts(i);'


To see the supported switches in jsish use -h

jsish -h
usage: jsi -h|--help|-v|--version|-d|--debug|-D|--debugui|-W|--websrv|-S|--safe|-Z|--zip|-H|--htmli|
    -J|-jsi|-C|--cssi|-i|--invoke CMD|-e|--eval SCRIPT|-t|--tracecall|-T|--typecheck OPT|-IOPT VAL|FILE arg arg ...

The available switches are:

Options Description
-h|--help Outputs jsish help, or module help
-v|--version Output jsish version information
-d|--debug Command-line debugger module
-D|--debugui Jsi web-based gui debugger
-W|--websrv Web server and start browser
-S|--safe Run a safe interpreter, script or interactive
-Z|--zip File zip utility
-H|--htmli Html preprocessor
-J|-jsi Javascript preprocessor
-c|--cdata FILE Process a Cdata definition
-C|--cssi Css preprocessor
-i|--invoke CMD Invoke command Sys module stored in /zvfs
-e|--eval SCRIPT Evaluate a script string from command-line
-t|--tracecall Trace function calls and returned values
-T|--typecheck OPT Set function type-checking level
-IOPT VAL Set an interp option

Help for module commands can similarly be displayed, eg:

jsish -d -h
/zvfs/lib/JsiUtil.jsi:121: error: throw: 
A command-line Debugger for Jsi scripts.

    -debug      false       // Debugging output
    -echoCmd    true        // Echo user cmds.
    -safe       false       // Debug program in a safe interp (untested)


which is used as:

jsish -d -debug true tests/while.js


Options are parameters handled by builtin commands. These get passed in an object:

var db = new Sqlite('/tmp/testsql.db',{maxStmts:1000, readonly:true});

Usually there is a conf() method providing access to options after creation:

Interp.conf(); // Dump all options
Interp.conf('strict'); // Get one option
Interp.conf({strict:false, maxDepth:99}); // Set one or more options.

Note some options may be readOnly. And an option that is initOnly may only be set at object creation time.

Internally, option parsing is implemented via C-Options.


There are several levels of introspection built-in to Jsi. One is displayed when calling an invalid method:

# Array.xxx()
error: 'Array' sub-commands are: concat fill filter forEach indexOf join lastIndexOf map pop push reverse shift sizeOf slice some sort splice unshift.    (at or near "xxx")

Another, is querying with the Info command:

# Info.platform()
{ crc:7, hasThreads:true, intSize:4, isBigEndian:false, numberSize:8, os:"linux", platform:"unix", pointerSize:8, timeSize:8, wideSize:8 }

# Info.cmds()
[  "Array", "Boolean", "File", "FileIO", "Function", "Interp", "Info", "JSON", "Math", "Number",
   "Object", "RegExp", "Signal", "Sqlite", "String", "Sys", "Websocket", "Zvfs", "assert", "clearInterval",
   "console", "decodeURI", "encodeURI", "exit", "source",
   "isFinite", "isNaN", "load", "parseFloat", "parseInt", "puts", "quote",
   "setInterval", "setTimeout", "format" ]

# Info.cmds('Array.*')
[ "concat", "fill", "filter", "forEach", "indexOf", "join", "lastIndexOf", "map", "pop", "push",
  "reverse", "shift", "sizeOf", "slice", "some", "sort", "splice", "unshift" ]

# Info.named()
[ "Socket", "Channel", "MySql", "WebSocket", "Sqlite", "Interp" ]

var ii = new Interp();
# Info.named('Interp')
[ "#Interp_1" ]

and so on.

Example Applications

Jsi is distributed with several demonstration web applications:

  • DebugUI: a Debugger user interface for Jsi scripts.
  • SqliteUI: a web user interface to Sqlite.
  • LedgerJS: an accounting program.

These can all be run as standalone applications.


You can use jsish as an enhanced replacement for #!/usr/bin/env. This lets you run scripts from the command line with default arguments:

#!/usr/local/bin/jsish -T Debug %s -Trace true myinput1.txt
puts(console.args.join(' '));

(there must be a %s and at least one argument)

From geany you can now run the script with F9, and step through warnings and errors.

This also works for logging messages: mytest2


Autocompletion can be set-up on unix by adding to .bashrc:

complete -W '-h --help -v --version -d --debug -D --debugui -u -unittest -s --safe -Z --zip \
  -S --sqliteui -W --websrv -H --htmli -J --jsi -c --cdata -C --cssi -m --module -e --eval \
  -T --typecheck -t --tracecall' -f '*.jsi'  'jsish'

or running:

make setup.

Next time you login you can use autocompletion with TAB.

This can make running jsish from the command-line a little nicer.



Geany is a convenient editor to use with Jsi. To enable Jsi file completion with Geany:

  • Copy tools/geany/filetypes.javascript to ~/.config/geany/filedefs/.
  • Open geany and navigate to Tools->Configuration Files->filetypes_extensions.conf, then:
  • Add "*.jsi;*.jsc" to Javascript, "*.wiki;*.htmli;" to HTML and "*.cssi;" to CSS
  • Keep the file tools/protos.jsi open in the editor so Geany knows how to complete Jsi functions.

Geany can also navigate through Jsi's gcc style scripting errors:

  • Start by editing a .jsi file.
  • From the Geany Build menu, select Set Build Commands.
  • Click on the first blank label in Javascript and enter Jsish.
  • In the command section enter the pathspec to jsish, eg. $HOME/bin/jsish %f
  • Click Ok

Now hit F8 to run the script. Upon errors, you should be able to navigate to the highlighted lines, and see warnings in the bottom pane.

Alternatively, you can just create a Makefile to run jsish.

Also, if using the logging feature in Jsi, you can also navigate through debug messages when using F9 or shell exec.

To run scripts that honor the shebang, repeat the above but set the command section to jsish -# %f.

Caveat: one limitation of Geany is that a function with a return type will likely not show up in the symbols list.


Here is how to setup/use vim with Jsi:
:set filetype javascript
:set makeprg=jsish\ %

Then to run scripts just use:


And much of what was said about navigation in Geany also applies to Vim.