Skip to content
← All examples

Example 24

Hook on symbol change

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

Category
Host: needs the terminal's data and engine
Permissions
None
Before you run it
attached to "Symbol changes" in the Script Hooks window
What it does
none (it prints; the Script Hooks log shows it)
How to run it
in TTT, open Script Hooks (palette, or the T0 Editor's View menu),
Language
>=0.1.1, <0.2.0
Host
>=0.1.5, <0.2.0
Needs
event >=0.1.0, <0.2.0

Source

// 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);
        }
    }
}