Imports
In NBCL, you can import modules and libraries.
INFO
A module is nothing but another .nbl file. Its just a fancy way to say it.
Importing Modules
The syntax for importing a modules is the import keyword, followed by the relative path to the module in quotations, followed by the as keyword, which is followed by a variable name of your choice.
Here is an example:
import "example.nbl" as exampleIf your directory looks something like this:
.
├─ main.nbl
└─ ui/
└─ button.nblAnd you want to import the button.nbl module, then you need to use the following code:
import "ui/button.nbl" as buttonHowever, this only imports the functions and the variables defined in the module. Not the components. Since components cannot be accessed under a namespace, you would need to import them like this:
# Functions and Varibles go under 'button'
# 'StyledButton' component is then included in.
import "ui/button.nbl" as button { StyledButton }To import all the components in, use the * wildcard.
# All the components in button is included
import "ui/button.nbl" as button { * }Importing Libraries
The syntax for importing libraries is similar to importing the modules, but much more straightforward. Its just the import keyword, followed by the library name, a dot, and the library item name.
Here is an example:
# Import the 'math' item
# from the 'std' library
import std.mathUsing the Imports
The imported items can be used like this:
import "my_cool_math.nbl" as cool_math
import std.math
# Functions can be accessed like this
math.sqrt(36)
cool_math.pow(5)
# Global variables can be accessed like this:
math.pi
cool_math.cool_number