Conditional Compilation
You can use the target ... { ... }-syntax to only include a piece of code when compiling to a specific target output format, these being c and js:
mod example
target c {
proc add(x, y) = x + y
}
proc main() {
target c {
println("We are compiling to C!")
println(add(5, 10))
}
target js {
println("We are compiling to JS!")
// 'add' isn't available
}
}
target c {
proc add(x, y) = x + y
}
proc main() {
target c {
println("We are compiling to C!")
println(add(5, 10))
}
target js {
println("We are compiling to JS!")
// 'add' isn't available
}
}