Lab 02 - VoltScript Project with VoltScript Library Module
Duration 15 min
What you will learn
You'll learn how to use atlas.json
and structure a VoltScript project. You'll also learn how to integrate external library modules with a Use
statement.
Prerequisites
- Lab 01 completed
Steps
The IDE
-
Create a new VS Code VoltScript Workspace folder called lab-02.
- Open Visual Studio Code.
-
From the Explorer view, click Open Folder.
-
Create a new folder in your user directory, with the name stated above.
- Select the newly created folder to open in VS Code.
atlas.json
-
Create a new
atlas.json
file:Note
The atlas.json file is the VoltScript equivalent of Node.js's
package.json
, Maven'spom.xml
or Rust'scargo.toml
. It defines metadata about your project (name, version, authors, license), dependencies, structure, and scripts.- Right-click in the empty pane and select New File from the context menu.
- Name the file
atlas.json
. - Type an opening curly brace "{" and press enter. VS Code automatically adds the closing curly brace "}".
-
If the PROBLEMS view isn't visible, select View → Problems. Note the validation errors, which will identify any required properties which are missing.
-
Set name to "lab02".
- Set version to "1.0.0".
- Set description to "Lab Number 2".
- Add the authors array. Add an array element with your name.
- Set sourceDir as "src". Set mainScripts as
main.vss
. - Use content assist (Ctrl + space) to see other elements that can be added.
- Set libsDir as "libs".
- Save the
atlas.json
.
libs directory
Note
In the same way that you can create Script Libraries and use them in Domino Designer with the Use
instruction, the same can be done in VoltScript. The terminology used to refer to these is "VoltScript Library Module".
- Right-click in the empty pane and select New Folder from the context menu. Name the directory "src".
- Right-click in the empty pane and select New Folder from the context menu. Name the directory "libs".
- Right-click the "libs" directory and select New File from the context menu. Name the file "Lab2Functions.vss".
- In the
.vss
file, addOption Declare
andOption Public
. -
Type Sub. Snippets will offer you "Sub...". Press Enter to select the snippet. The following code will be inserted.
-
ProcedureName
is selected. Rename the sub "PrintMessage" and press tab to move to the next variable. ParameterList
is selected. Overtype it withmessage as String
.- Move down to the body of the sub, and type
Print message
. - Move out of the sub, type "fun", and select the "Function..." snippet by pressing Enter.
FunctionName
is selected. Rename the function "Square". Press tab to move to the next variable.ParameterList
is selected. Overtype it withvalue as Integer
.ReturnType
is selected. Overtype it withInteger
. Only the first instance of this will be replaced and a compilation error will remain "Variable not declared RETURNVALUE".-
On the first line of the function, type
value *= value
.Tip
Additional mathematical assignment operators have been added to the VoltScript language. In addition to the obvious
++
and--
options,+=
,-=
,*=
and/=
(with its alias\=
) have also been added. -
Amend the last line of the function to
Square = value
. - Save the file.
Main script
- Right-click the "src" directory and select New File from the context menu. Name the file
main.vss
. - In the
.vss
file, addOption Declare
andOption Public
. -
Add the statement
Use "../libs/Lab2Functions"
.Warning
VS Code might try to help you out here by providing typeahead here. If so, be sure to remove the
.vss
from the end of the library name!
Note
We can use relative paths in the
Use
statement. Using forward slashes make theUse
statements cross-platform. Paths to Library Modules and downstream Library Modules (modules used in other Library Modules) need to work from any script opened. So all Library Modules should be at the same level of the hierarchy. -
Add a
Sub Initialize
. - Add
Call PrintMessage("Hello World")
. - Add
Call PrintMessage("4 x 4 = " & Square(4))
. - Press Ctrl+Shift+P (Cmd+Shift+P on Mac), then select VoltScript: Save & Run Script. (You can start typing "VoltScript" to filter the available commands).
-
Press the
Enter
key to confirm your input (no script arguments are necessary).Success
A VoltScript terminal will open in your workspace and display the result of your script.
How to check
Print to console:
The completed lab is available on GitHub.
Things to explore
-
Change the content of the Square() function to
Return value * value
.Note
The Return keyword is used to immediately cease operations and exit a method (Sub, Function or Property). It the method is a Function or Property Get, the Return keyword will also return the subsequent value to the calling code.
-
Test downstream VoltScript Library Modules (one module that uses another).
- Test to understand how relative paths need to work from all levels of the hierarchy.
Next step
Proceed to Lab 03a - Using VoltScript Dependency Management for VSEs and VSS Libraries.