Struct
Console program59 lines of .st132 lines of generated C
The sum of 5 and 7 is 12
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "@latest"
}
}
}main.st
ability "function" "add" {
params = [{ name = "d", type = Pointer, to = MyData }]
body = [ability.set.Out]
}
ability "set" "Out" {
target = d.outval
value = d.inval1 + d.inval2
}
ability "set" "In1" {
target = ability.value.data.inval1
value = 5
}
ability "set" "In2" {
target = ability.value.data.inval2
value = 7
}
ability "call" "Add" {
function = ability.function.add
args = [address_of(ability.value.data)]
depends_on = [ability.set.In1, ability.set.In2]
}
ability "print" "Show" {
message = "The sum of ${data.value.data.current.inval1} and ${data.value.data.current.inval2} is ${data.value.data.current.outval}"
depends_on = [ability.call.Add]
}vars.st
ability "struct" "MyData" {
fields = [
{ name = "inval1", type = Int },
{ name = "inval2", type = Int },
{ name = "outval", type = Int },
]
}
ability "value" "data" {
type = MyData
}
data "value" "data" {
of = ability.value.data
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.function.add
+ ability.set.Out
+ ability.set.In1
+ ability.set.In2
+ ability.call.Add
+ ability.print.Show
+ ability.struct.MyData
+ ability.value.data
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.c
To inspect this generated file, select C in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
cd c-struct # a folder holding the .st files above
structop init
structop plan
structop apply