From: tateishi@... (Tateishi Takaaki) Date: 1997-10-24T08:07:36+09:00 Subject: [ruby-list:5127] Re: ruby & tk(wish) 立石です。 >> ;; wishでの変数をrubyでそのまま文字列から扱える >> ;; ようにできればいいなぁとか思ってます。 >> ;; たとえば >> ;; a = "button1"; >> ;; Tk.write("button $a"); >> ;; でwishでの >> ;; set a "button1" >> ;; button $a >> ;; と同等の操作ができTk.writeでwishでの戻り値が返って >> ;; くるとか、、、、、、(^^; >> ;; 戻り値を受け取ることってできるのでしょうか? これをスクリプトレベルで実現させようとして次のような 簡単なスクリプトを書きましたが、なんとか戻り値を得る ことはできないのでしょうか? また、rubyでの大域変数をwishへ反映させることはできるのですが その逆は可能でしょうか? 例' a = Wish.new a.init $button1 = ".b1" $button2 = ".b2" a.command("button $button1 -text Quit -command exit") a.command("button $button2 -text {do nothing}") a.command("pack $button1 $button2") ...... ..do anything... ...... a.close ----------------------------------------------------- # wish.rb # 1997.10.24 Takaaki.Tateishi class Wish def init @wish = open("|wish","r+") end def replace(str) line = str.split(" ") arg = [] for i in 0 .. (line.length-1) if line[i] =~ /$[a-zA-Z0-9_]+/ then line[i] = eval(line[i]) end end line.join(" ") end def command(str) @wish.write("set tcl_result [" + replace(str) + "]\n") end def close self.command("exit") @wish.close end end -------------------------------------------------------------- -------------------------------------------------- Takaaki Tateishi [tateishi@pluto.dti.ne.jp] [http://www.pluto.dti.ne.jp/~tateishi] --------------------------------------------------