Files
mgmt/examples/lang/datetime3.mcl
James Shubin 6de7d8b254 lang: funcs: Catch non-specific type build error
If you had ambiguous code, and specified an invalid type, this could
sneak through and become a runtime error, instead of a compile-time
error. We fix this and add a test.
2024-07-31 17:29:42 -04:00

20 lines
648 B
Plaintext

import "datetime"
import "sys"
import "example"
$secplusone = datetime.now() + $ayear
# note the order of the assignment (year can come later in the code)
$ayear = 60 * 60 * 24 * 365 # is a year in seconds (31536000)
$tmplvalues = struct{year => $secplusone, load => $theload, vumeter => $vumeter,}
$theload float = sys.load()->x1 # ambiguous so we specify the type!
$vumeter = example.vumeter("====", 10, 0.9)
file "/tmp/mgmt/datetime" {
state => $const.res.file.state.exists,
content => template("Now + 1 year is: {{ .year }} seconds, aka: {{ datetime_print .year }}\n\nload average: {{ .load }}\n\nvu: {{ .vumeter }}\n", $tmplvalues),
}