lys
lys copied to clipboard
how do I import functions?
you can reference functions by its module and name using fully qualified names
fun main(): void = {
support::env::printf("number is %d", 1)
}
Or you can import the whole module and the names will be available locally
import support::env
fun main(): void = {
printf("number is %d", 1)
}
The fully::qualified::names represent the path of the module starting at the root of the project / standard library.
So if you have a structure like:
// lib/folder/file.lys
struct NumberWrapper(number: i32)
fun add(a: NumberWrapper, b: NumberWrapper): NumberWrapper =
NumberWrapper(a.number + b.number)
// lib/main.lys
import lib::folder::file
fun main(): i32 = add(NumberWrapper(1), NumberWrapper(2))
which is the same as
fun main(): i32 =
lib::folder::file::add(
lib::folder::file::NumberWrapper(1),
lib::folder::file::NumberWrapper(2)
)