summaryrefslogtreecommitdiff
path: root/ext/tk
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-14 14:59:04 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-14 14:59:04 +0000
commit011a8516963e68a348d695064d686b80fb93b9fa (patch)
tree27a298f956da4a703355ade734c8f8de96be9fcb /ext/tk
parent0964c4781652bcdfcf940017722164d2effc69ee (diff)
* 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
Diffstat (limited to 'ext/tk')
-rw-r--r--ext/tk/lib/multi-tk.rb22
-rw-r--r--ext/tk/sample/safe-tk.rb38
2 files changed, 44 insertions, 16 deletions
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)