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

サンプル 24

Hook on symbol change

a hook for "a symbol changes": say what the chart was and what it

カテゴリ
Host:ターミナルのデータとエンジンが必要
権限
なし
実行する前に
attached to "Symbol changes" in the Script Hooks window
何をするか
none (it prints; the Script Hooks log shows it)
実行方法
in TTT, open Script Hooks (palette, or the T0 Editor's View menu),
言語
>=0.1.1, <0.2.0
ホスト
>=0.1.5, <0.2.0
必要なもの
event >=0.1.0, <0.2.0

ソース

// Purpose: a hook for "a symbol changes": say what the chart was and what it
// became. The smallest useful hook — it only reads the event.
// Category: host
// Permissions: none
// Preconditions: attached to "Symbol changes" in the Script Hooks window
// Side effects: none (it prints; the Script Hooks log shows it)
// Run: in TTT, open Script Hooks (palette, or the T0 Editor's View menu),
// press "+ Add script" under "Symbol changes", choose this file. Run by
// hand it reads a "manual" event and says so.

lang ">=0.1.1, <0.2.0";
host "ttt" ">=0.1.5, <0.2.0";
requires "event" ">=0.1.0, <0.2.0";

fn main() {
    let e = event.current();
    if e.kind != "symbol_changed" {
        print("not a symbol change (this was a " + e.kind + " event); nothing to report");
    } else {
        match e.symbol {
            Some(s) => print("a chart now shows " + s),
            None => print("the symbol is not known"),
        }
        for line in e.data {
            print("  " + line);
        }
    }
}