StructOp Handbook
Contents Examples Commands
Handbook / Application language

Abilities and functions

Use an ability to declare behaviour. Control when it runs with dependencies or a parent body. Define a function when several places need to call the same behaviour.

On this page

Abilities#

An ability is ability "kind" "Name". The kind comes from a provider; the name is yours and must be unique per kind. Abilities refer to each other as ability.kind.Name.

ability "loop" "Game" {
    condition = !data.value.done.current
    body      = [ability.call.Turn, ability.print.Status]
}

Here Second is written first in the list but waits for First, so the program prints first and then second, and the plan lists them in that order.

ability "if" "Choose" {
    condition = true
    then      = [ability.print.Second, ability.print.First]
}

ability "print" "Second" {
    message    = "second"
    depends_on = [ability.print.First]
}

ability "print" "First" {
    message = "first"
}

Functions#

ability "function" "twice" {
    params  = [{ name = "x", type = Int }]
    returns = Int
    return  = x * 2
}

ability "call" "Show" {
    function = ability.function.twice
    args     = [21]
    result   = ability.value.answer
}

Functions take params, locals and a body (optional), may return an expression, and can be called inside expressions (${twice(var.n) + 1}). Structs are passed as Pointer parameters.

The guided tour shows how a program calls a function from a loop. Look up the attributes for an individual ability in the provider registry.