Read
Console program68 lines of .st145 lines of generated C
Hello from a file.
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 "open" "In" {
path = "input.txt"
mode = read
file = ability.value.fp
body = [ability.loop.Copy]
}
ability "loop" "Copy" {
condition = true
body = [ability.read.Next, ability.append.Add]
}
ability "read" "Next" {
file = ability.value.fp
target = ability.value.c
at_end = [ability.break.Done]
}
ability "break" "Done" {
}
ability "append" "Add" {
target = ability.value.line
value = "${data.value.c.current}"
}
ability "print" "Show" {
message = "${data.value.line.current}"
depends_on = [ability.open.In]
}vars.st
ability "value" "fp" {
type = File
}
data "value" "fp" {
of = ability.value.fp
}
ability "value" "c" {
type = Char
}
data "value" "c" {
of = ability.value.c
}
ability "value" "line" {
type = String
size = 64
}
data "value" "line" {
of = ability.value.line
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.open.In
+ ability.loop.Copy
+ ability.read.Next
+ ability.break.Done
+ ability.append.Add
+ ability.print.Show
+ ability.value.fp
+ ability.value.c
+ ability.value.line
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-read # a folder holding the .st files above
structop init
structop plan
structop apply