lang, test, examples: lang: Use new syntax for structlookup
Sugar makes the world go round.
This commit is contained in:
@@ -8,7 +8,7 @@ $ayear = 60 * 60 * 24 * 365 # is a year in seconds (31536000)
|
|||||||
|
|
||||||
$tmplvalues = struct{year => $secplusone, load => $theload,}
|
$tmplvalues = struct{year => $secplusone, load => $theload,}
|
||||||
|
|
||||||
$theload = structlookup(sys.load(), "x1")
|
$theload = sys.load()->x1
|
||||||
|
|
||||||
if 5 > 3 {
|
if 5 > 3 {
|
||||||
file "/tmp/mgmt/datetime" {
|
file "/tmp/mgmt/datetime" {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ $ayear = 60 * 60 * 24 * 365 # is a year in seconds (31536000)
|
|||||||
|
|
||||||
$tmplvalues = struct{year => $secplusone, load => $theload, vumeter => $vumeter,}
|
$tmplvalues = struct{year => $secplusone, load => $theload, vumeter => $vumeter,}
|
||||||
|
|
||||||
$theload = structlookup(sys.load(), "x1")
|
$theload = sys.load()->x1
|
||||||
|
|
||||||
$vumeter = example.vumeter("====", 10, 0.9)
|
$vumeter = example.vumeter("====", 10, 0.9)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ file "/tmp/mgmt/systemload" {
|
|||||||
|
|
||||||
$tmplvalues = struct{load => $theload, threshold => $threshold,}
|
$tmplvalues = struct{load => $theload, threshold => $threshold,}
|
||||||
|
|
||||||
$theload = structlookup(sys.load(), "x1")
|
$theload = sys.load()->x1
|
||||||
$threshold = 1.5 # change me if you like
|
$threshold = 1.5 # change me if you like
|
||||||
|
|
||||||
# simple hysteresis implementation
|
# simple hysteresis implementation
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import "sys"
|
|||||||
|
|
||||||
$theload = sys.load()
|
$theload = sys.load()
|
||||||
|
|
||||||
$x1 = structlookup($theload, "x1")
|
$x1 = $theload->x1
|
||||||
$x5 = structlookup($theload, "x5")
|
$x5 = $theload->x5
|
||||||
$x15 = structlookup($theload, "x15")
|
$x15 = $theload->x15
|
||||||
|
|
||||||
print "print1" {
|
print "print1" {
|
||||||
msg => fmt.printf("load average: %f, %f, %f", $x1, $x5, $x15),
|
msg => fmt.printf("load average: %f, %f, %f", $x1, $x5, $x15),
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ import "fmt"
|
|||||||
|
|
||||||
$st = struct{f1 => 42, f2 => true, f3 => 3.14,}
|
$st = struct{f1 => 42, f2 => true, f3 => 3.14,}
|
||||||
|
|
||||||
$f1 = structlookup($st, "f1")
|
$f1 = $st->f1
|
||||||
|
|
||||||
print "print1" {
|
print "print1" {
|
||||||
msg => fmt.printf("f1 field is: %d", $f1),
|
msg => fmt.printf("f1 field is: %d", $f1),
|
||||||
}
|
}
|
||||||
|
|
||||||
$f2 = structlookup($st, "f2")
|
$f2 = $st->f2
|
||||||
|
|
||||||
print "print2" {
|
print "print2" {
|
||||||
msg => fmt.printf("f2 field is: %t", $f2),
|
msg => fmt.printf("f2 field is: %t", $f2),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
-- main.mcl --
|
-- main.mcl --
|
||||||
$st struct{x str} = struct{x => "hello", x => "world",}
|
$st struct{x str} = struct{x => "hello", x => "world",}
|
||||||
test structlookup($st, "x") {}
|
test $st->x {}
|
||||||
-- OUTPUT --
|
-- OUTPUT --
|
||||||
# err: errInit: duplicate struct field name of: `x`
|
# err: errInit: duplicate struct field name of: `x`
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
-- main.mcl --
|
-- main.mcl --
|
||||||
$st0 struct{x str} = struct{x => "hello",}
|
$st0 struct{x str} = struct{x => "hello",}
|
||||||
test structlookup($st0, "x") {}
|
test $st0->x {}
|
||||||
|
|
||||||
$st1 = struct{y => "world",}
|
$st1 = struct{y => "world",}
|
||||||
test structlookup($st1, "y") {}
|
test $st1->y {}
|
||||||
|
|
||||||
$st2 = struct{x => true, y=> 42, z => "hello world",}
|
$st2 = struct{x => true, y=> 42, z => "hello world",}
|
||||||
test structlookup($st2, "z") {}
|
test $st2->z {}
|
||||||
-- OUTPUT --
|
-- OUTPUT --
|
||||||
Vertex: test[hello world]
|
Vertex: test[hello world]
|
||||||
Vertex: test[hello]
|
Vertex: test[hello]
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
-- main.mcl --
|
-- main.mcl --
|
||||||
$st0 = struct{x1 => 1.0, x5 => 2.1, x15 => 3.2,}
|
$st0 = struct{x1 => 1.0, x5 => 2.1, x15 => 3.2,}
|
||||||
$s0a = if structlookup($st0, "x1") == 1.0 {
|
$s0a = if $st0->x1 == 1.0 {
|
||||||
"passed0a"
|
"passed0a"
|
||||||
} else {
|
} else {
|
||||||
"failed"
|
"failed"
|
||||||
}
|
}
|
||||||
test $s0a {}
|
test $s0a {}
|
||||||
$s0b = if structlookup($st0, "x5") == 2.1 {
|
$s0b = if $st0->x5 == 2.1 {
|
||||||
"passed0b"
|
"passed0b"
|
||||||
} else {
|
} else {
|
||||||
"failed"
|
"failed"
|
||||||
}
|
}
|
||||||
test $s0b {}
|
test $s0b {}
|
||||||
$s0c = if structlookup($st0, "x15") == 3.2 {
|
$s0c = if $st0->x15 == 3.2 {
|
||||||
"passed0c"
|
"passed0c"
|
||||||
} else {
|
} else {
|
||||||
"failed"
|
"failed"
|
||||||
@@ -20,7 +20,7 @@ $s0c = if structlookup($st0, "x15") == 3.2 {
|
|||||||
test $s0c {}
|
test $s0c {}
|
||||||
|
|
||||||
$st1 struct{x1 float; x5 float; x15 float} = struct{x1 => 1.0, x5 => 2.1, x15 => 3.2,}
|
$st1 struct{x1 float; x5 float; x15 float} = struct{x1 => 1.0, x5 => 2.1, x15 => 3.2,}
|
||||||
$s1 = if structlookup($st1, "x5") == 2.1 {
|
$s1 = if $st1->x5 == 2.1 {
|
||||||
"passed1"
|
"passed1"
|
||||||
} else {
|
} else {
|
||||||
"failed"
|
"failed"
|
||||||
@@ -28,7 +28,7 @@ $s1 = if structlookup($st1, "x5") == 2.1 {
|
|||||||
test $s1 {}
|
test $s1 {}
|
||||||
|
|
||||||
$st2 = struct{x1 => 1.0, x5 => 2.1, x15 => 3.2,}
|
$st2 = struct{x1 => 1.0, x5 => 2.1, x15 => 3.2,}
|
||||||
$s2 = if structlookup($st2, "x5") == 2.1 {
|
$s2 = if $st2->x5 == 2.1 {
|
||||||
"passed2"
|
"passed2"
|
||||||
} else {
|
} else {
|
||||||
"failed"
|
"failed"
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
-- main.mcl --
|
-- main.mcl --
|
||||||
$st0 struct{x str} = struct{x => "hello",}
|
$st0 struct{x str} = struct{x => "hello",}
|
||||||
test structlookup($st0, "x") {}
|
test $st0->x {}
|
||||||
|
|
||||||
$st1 = struct{y => "world",}
|
$st1 = struct{y => "world",}
|
||||||
test structlookup($st1, "y") {}
|
test $st1->y {}
|
||||||
|
|
||||||
$st2 = struct{x => true, y => 42, z => "hello world",}
|
$st2 = struct{x => true, y => 42, z => "hello world",}
|
||||||
test structlookup($st2, "z") {}
|
test $st2->z {}
|
||||||
test "foo" {
|
test "foo" {
|
||||||
mixedstruct => struct{
|
mixedstruct => struct{
|
||||||
somebool => true,
|
somebool => true,
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ import "sys"
|
|||||||
|
|
||||||
\$theload = sys.load()
|
\$theload = sys.load()
|
||||||
|
|
||||||
\$x1 = structlookup(\$theload, "x1")
|
\$x1 = \$theload->x1
|
||||||
\$x5 = structlookup(\$theload, "x5")
|
\$x5 = \$theload->x5
|
||||||
\$x15 = structlookup(\$theload, "x15")
|
\$x15 = \$theload->x15
|
||||||
|
|
||||||
file "${tmpdir}/loadavg" {
|
file "${tmpdir}/loadavg" {
|
||||||
content => fmt.printf("load average: %f, %f, %f\n", \$x1, \$x5, \$x15),
|
content => fmt.printf("load average: %f, %f, %f\n", \$x1, \$x5, \$x15),
|
||||||
|
|||||||
Reference in New Issue
Block a user