1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nagai 2004-09-14 14:59:04 +00:00
parent 0964c47816
commit 011a851696
3 changed files with 49 additions and 16 deletions

View file

@ -1,3 +1,8 @@
Tue Sep 14 23:54:11 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* 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 <dave@pragprog.com>
* lib/rdoc/ri/ri_formatter.rb (RI::TextFormatter::TextFormatter.for):

View file

@ -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

View file

@ -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)