Gjs のサンプルコードを探していると???となることが多い。
new キーワードの有無がマチマチ、パラメータが JSON か否か。
JSON イラネーだろ!と外すと動かないし、もう何がなんだか。
海外でしかサンプルコードが見つからないから英語でよく解らない。
だったけどやっと解決した。
#!/usr/bin/gjs
const Gio = imports.gi.Gio;
/* After new @ Params ALl */
let uostream = Gio.UnixOutputStream.new(0, false);
let dostream = Gio.DataOutputStream.new(uostream);
dostream.put_string("Enter Some String :", null);
let uistream = Gio.UnixInputStream.new(1, false);
let distream = Gio.DataInputStream.new(uistream);
[txt, len] = distream.read_line_utf8(null);
print(txt);
/* Before new @ Params Json */
let uostream2 = new Gio.UnixOutputStream({fd: 0});
let dostream2 = new Gio.DataOutputStream({base_stream: uostream2});
dostream2.put_string("Enter Some String :", null);
let uistream2 = new Gio.UnixInputStream({fd: 1});
let distream2 = new Gio.DataInputStream({base_stream: uistream2});
[txt2, len2] = distream2.read_line_utf8(null);
print(txt2);
コレだけのことだったのかYO!
どのオブジェクトも new はキーワードでもメソッドでもいい。
メソッドにしたら C 同様にパラメーターを全部埋める。
キーワードにしたら JSON で、null やゼロなら埋めなくてよし。
どっちも面倒臭い。
new も null パラメーターもいらない、としてくれるのが一番なんだけど。
ついでにセミコロン、ってソレが PyGObject だった。
GObject Introspection って今はこんなに沢山の言語から使えるのね。
GNOME 自前の Gjs でさえ情報が少ないのに他はどうするんだって感じですが。
結局 Python が一番情報が多いのは GTK2 時代と同じですね。
ところで。
let
Google Chrome, Firefox がいつのまにか let 宣言に対応しているね。
後は Safari だけだな、osascript でも使えないけど。







