Software script management
| See also: Application of Programme Model Control. |
All engee.script programme control methods are presented here. For an introduction to engee methods, please refer to the article Public methods of program management.
script methods
#
engee.script.edit — Function
engee.script.edit(path::String)
Opens the interactive script located at the path path (including the filename and extension). If no such file exists, an empty script file is created at the specified path and opened in the editor. If the extension specified in path differs from ‘.ngscript’, the function will return the error ‘ ErrorException("path should end with '.ngscript' extension")` ’.
Examples
# Opens the script file.ngscript in the Script Editor Engee
engee.script.edit( "file.ngscript" )
#
engee.script.run — Function
engee.script.run(path::String; isolate::Bool = false)
Runs the script at the specified path. Returns the result of the last top-level expression in the script.
Arguments
-
path::String: the absolute path to the script. -
isolate::Bool = false: if set totrue, the script is executed in an isolated environment. By default, it is set tofalse. If set tofalse, the script is executed in the main user environment (the Main module). All variables declared globally or at the top level are preserved after execution. If set totrue, the script runs in a temporary isolated environment. All variables created during execution are not retained after the script has finished.
Examples
Consider the file foo.ngscript with a single code cell:
x = 10
y = try
push!(a, :foo) # We try to add:foo to the existing array `a`
5 # If everything is OK — we set y to 5
catch _
3 # If an error occurred — we set y to 3
end
x + y # We return the sum of x and y
Execution in the user environment (isolate = false) will modify the variables x and y, and will also add :foo to the array а:
a = Symbol[:bar, :baz] # Original array
x = y = 0 # Variables before the script runs
(engee.script.run("foo.ngscript"), x, y, a)
# ⇒ (15, 10, 5, [:bar, :baz, :foo])
# The script modified the variables x and y, and also added :foo to the array a
When run in a sandboxed environment (isolate = true), the script will not affect external variables and the changes will not be saved:
# Original array
a = Symbol[:bar, :baz]
# Variables before the script was run
x = y = 0
(engee.script.run("foo.ngscript"; isolate = true), x, y, a)
# ⇒ (13, 0, 0, [:bar, :baz])
# The script did not affect external variables — the changes were not saved