Inputs and values
Use a variable for a build-time setting, a parameter for a command-line argument, and a value for data the running program changes.
On this page
Variables and constants#
variable "count" {
description = "How many times to say it"
type = Int
default = 3
}
constant "SCREEN_WIDTH" {
type = Int
default = 80
}count = 5Inside expressions they are var.count and const.SCREEN_WIDTH. A .stvars value replaces the default; structop test runs can replace them again. A program never writes a variable: data that changes lives in a value.
Parameters#
parameter "n" {
type = Int
position = 1
}
parameter "verbose" {
type = Bool
default = false
}Parameters become a generated argument parser: positional ones by position, the others by name (--verbose, --scale 2.5), and one rest = true parameter collects what remains. Run with structop apply -- --verbose 3 --scale 2.5 bob a b.
Values and data#
ability "value" "score" {
description = "Points so far"
type = Int
initial = 0
}
data "value" "score" {
of = ability.value.score
}
ability "set" "Add" {
target = ability.value.score
value = data.value.score.current + var.count
}An ability "value" is the only storage a program changes. It takes any type, with initial in place of default. Abilities that write name the value itself (target, response, result, list, counter); everything else reads it through a data block, here data.value.score.current. Reading the value itself (${ability.value.score}) is an error, read a value through a data block: data.value.score.current; only a handle a library gave you, such as a database connection, is passed on whole (db = ability.value.db). Information moves between abilities only through data blocks: providers add their own kinds, such as data "text" (an entry's text) or data "event" (the widget whose handler is running). A value listed in a function's body is a local of that function. In C the values are fields of one struct st_state in main(), passed as st to the functions that use them; in Rust they are fields of State.
Follow the command-line flags example to trace arguments from the shell into the program. The value example shows a write followed by a read.