本文へ移動
← すべてのサンプル

サンプル 15

Capabilities

what this terminal offers programs right now, contract by

カテゴリ
Workspace:チャートやパネルを読む・変更する
権限
none (it describes; it grants nothing)
実行する前に
running inside TTT (the CLI has no host)
何をするか
none
実行方法
in TTT, open "T0 Lang", open this file, Run. Then grant something
言語
>=0.1.1, <0.2.0
ホスト
>=0.1.3, <0.2.0
必要なもの
capabilities >=0.1.0, <0.2.0

ソース

// Purpose: what this terminal offers programs right now, contract by
// contract: what can run here (available) and what this session has
// granted (authorized) — two different things.
// Category: workspace
// Permissions: none (it describes; it grants nothing)
// Preconditions: running inside TTT (the CLI has no host)
// Side effects: none
// Run: in TTT, open "T0 Lang", open this file, Run. Then grant something
// and Run again: the "granted" counts change, the "available" ones do not.

lang ">=0.1.1, <0.2.0";
host "ttt" ">=0.1.3, <0.2.0";
requires "capabilities" ">=0.1.0, <0.2.0";
import std.list;

fn main() {
    let all = capabilities.operations();
    let mut contracts: List<String> = [];
    for op in all {
        if !list.contains(contracts, op.contract) {
            contracts.push(op.contract);
        }
    }
    for name in contracts {
        let mut total = 0;
        let mut available = 0;
        let mut usable = 0;
        let mut version = "";
        for op in all {
            if op.contract == name {
                total = total + 1;
                version = op.version;
                if op.available {
                    available = available + 1;
                    if op.granted {
                        usable = usable + 1;
                    }
                }
            }
        }
        print(name + " " + version + ": " + to_string(total) + " operations, " + to_string(available) + " available here, " + to_string(usable) + " of those granted");
    }
    for op in all {
        match op.why {
            Some(why) => print("  not here: " + op.contract + "." + op.operation + " (" + why + ")"),
            None => {}
        }
    }
}