From 011a8516963e68a348d695064d686b80fb93b9fa Mon Sep 17 00:00:00 2001 From: nagai Date: Tue, 14 Sep 2004 14:59:04 +0000 Subject: [PATCH] * ext/tk/lib/multi-tk.rb: MultiTkIp#eval_string was en-bugged by the previous changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/tk/lib/multi-tk.rb | 22 ++++++++++------------ ext/tk/sample/safe-tk.rb | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index a1c6014b28..ed8bae6f1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Sep 14 23:54:11 2004 Hidetoshi NAGAI + + * ext/tk/lib/multi-tk.rb: MultiTkIp#eval_string was en-bugged by + the previous changes. + Tue Sep 14 23:45:44 2004 Dave Thomas * lib/rdoc/ri/ri_formatter.rb (RI::TextFormatter::TextFormatter.for): diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb index d54c6a5022..2d758fc28c 100644 --- a/ext/tk/lib/multi-tk.rb +++ b/ext/tk/lib/multi-tk.rb @@ -1200,17 +1200,6 @@ end class MultiTkIp # instance method def eval_proc_core(req_val, cmd, *args) - # cmd string ==> proc - if cmd.kind_of?(String) - xcmd = cmd - xargs = args - cmd = proc{ - $SAFE=@safe_level[0] - TkComm._get_eval_string(eval(xcmd, *xargs)) - } - args = [] - end - # check unless cmd.kind_of?(Proc) || cmd.kind_of?(Method) raise RuntimeError, "A Proc/Method object is expected for the 'cmd' argument" @@ -1314,7 +1303,16 @@ class MultiTkIp *args) end alias call eval_proc - alias eval_string eval_proc + + def eval_string(cmd, *eval_args) + # cmd string ==> proc + unless cmd.kind_of?(String) + raise RuntimeError, "A String object is expected for the 'cmd' argument" + end + + eval_proc_core(true, proc{|safe| $SAFE=safe; Kernel.eval(cmd, *eval_args)}) + end + alias eval_str eval_string end class << MultiTkIp diff --git a/ext/tk/sample/safe-tk.rb b/ext/tk/sample/safe-tk.rb index 1a8f0fc770..48d9a6bfcb 100644 --- a/ext/tk/sample/safe-tk.rb +++ b/ext/tk/sample/safe-tk.rb @@ -5,8 +5,11 @@ require "multi-tk" ############################### -TkLabel.new(:text=>'Default Master Ipnterpreter').pack(:padx=>5, :pady=>7) +TkLabel.new(:text=>'This is the Default Master Ipnterpreter').pack(:padx=>5, :pady=>3) TkButton.new(:text=>'QUIT', :command=>proc{exit}).pack(:pady=>3) +TkFrame.new(:borderwidth=>2, :height=>3, + :relief=>:sunken).pack(:fill=>:x, :expand=>true, + :padx=>10, :pady=>7) ############################### @@ -16,20 +19,27 @@ ip = MultiTkIp.new_safe_slave(1) puts "\n---- create procs ----------" puts 'x = proc{p [\'proc x\', "$SAFE==#{$SAFE}"]; exit}' x = proc{p ['proc x', "$SAFE==#{$SAFE}"]; exit} +TkLabel.new(:text=>'x = proc{p [\'proc x\', "$SAFE==#{$SAFE}"]; exit}', + :anchor=>:w).pack(:fill=>:x) puts 'y = proc{|label| p [\'proc y\', "$SAFE==#{$SAFE}", label]; label.text($SAFE)}' y = proc{|label| p ['proc y', "$SAFE==#{$SAFE}", label]; label.text($SAFE)} +TkLabel.new(:text=>'y = proc{|label| p [\'proc y\', "$SAFE==#{$SAFE}", label]; label.text($SAFE)}', + :anchor=>:w).pack(:fill=>:x) puts 'z = proc{p [\'proc z\', "$SAFE==#{$SAFE}"]; exit}' z = proc{p ['proc z', "$SAFE==#{$SAFE}"]; exit} +TkLabel.new(:text=>'z = proc{p [\'proc z\', "$SAFE==#{$SAFE}"]; exit}', + :anchor=>:w).pack(:fill=>:x) puts "\n---- call 1st eval_proc ----------" print 'lbl = ' p lbl = ip.eval_proc{ - TkLabel.new(:text=>"1st eval_prpc : $SAFE == #{$SAFE}").pack + TkLabel.new(:text=>"1st eval_proc : $SAFE == #{$SAFE}").pack f = TkFrame.new.pack TkLabel.new(f, :text=>"$SAFE == ").pack(:side=>:left) + # TkLabel.new(f, :text=>" (<-- 'lbl' widget is here)").pack(:side=>:right) l = TkLabel.new(f).pack(:side=>:right) TkButton.new(:text=>':command=>proc{l.text($SAFE)}', @@ -48,7 +58,7 @@ ip.safe_level = 3 puts "\n---- call 2nd eval_proc ----------" p ip.eval_proc(proc{ - TkLabel.new(:text=>"2nd eval_prpc : $SAFE == #{$SAFE}").pack + TkLabel.new(:text=>"2nd eval_proc : $SAFE == #{$SAFE}").pack f = TkFrame.new.pack TkLabel.new(f, :text=>"$SAFE == ").pack(:side=>:left) l = TkLabel.new(f, :text=>$SAFE).pack(:side=>:right) @@ -69,12 +79,32 @@ p ip.eval_proc(proc{ :padx=>10, :pady=>7) }) +puts "\n---- call 1st and 2nd eval_str ----------" +p bind = ip.eval_str(' + TkLabel.new(:text=>"1st and 2nd eval_str : $SAFE == #{$SAFE}").pack + f = TkFrame.new.pack + TkLabel.new(f, :text=>"$SAFE == ").pack(:side=>:left) + l = TkLabel.new(f, :text=>$SAFE).pack(:side=>:right) + TkButton.new(:text=>":command=>proc{y.call(l)}", + :command=>proc{y.call(l)}).pack(:fill=>:x, :padx=>5) + binding +', binding) + +p ip.eval_str(" + TkButton.new(:text=>':command=>proc{ l.text = $SAFE }', + :command=>proc{ l.text = $SAFE }).pack(:fill=>:x, :padx=>5) + TkFrame.new(:borderwidth=>2, :height=>3, + :relief=>:sunken).pack(:fill=>:x, :expand=>true, + :padx=>10, :pady=>7) +", bind) puts "\n---- change the safe slave IP's safe-level ==> 4 ----------" ip.safe_level = 4 puts "\n---- call 3rd and 4th eval_proc ----------" -p ip.eval_proc{ TkLabel.new(:text=>"3rd+ eval_prpc : $SAFE == #{$SAFE}").pack } +p ip.eval_proc{ + TkLabel.new(:text=>"3rd and 4th eval_proc : $SAFE == #{$SAFE}").pack +} p ip.eval_proc{ TkButton.new(:text=>':command=>proc{ lbl.text = $SAFE }', :command=>proc{ lbl.text = $SAFE }).pack(:fill=>:x, :padx=>5)