summaryrefslogtreecommitdiff
path: root/ext/tk/sample
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-13 07:25:02 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-13 07:25:02 +0000
commitd5188667bc966360e4feca9d3c46b357d2dd8d47 (patch)
tree41fe381eb1fb509e40dc3c9b49716fc38ecdac0c /ext/tk/sample
parent1e2ea43fe82e95355fdb1cb378df233c9f806bbc (diff)
* ext/tk/lib/multi-tk.rb: MultiTkIp.new_master and new_slave accept
safe-level value argument git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample')
-rw-r--r--ext/tk/sample/tkoptdb-safeTk.rb33
1 files changed, 20 insertions, 13 deletions
diff --git a/ext/tk/sample/tkoptdb-safeTk.rb b/ext/tk/sample/tkoptdb-safeTk.rb
index ebbc7b486f..b41c856d5a 100644
--- a/ext/tk/sample/tkoptdb-safeTk.rb
+++ b/ext/tk/sample/tkoptdb-safeTk.rb
@@ -4,15 +4,16 @@ require 'multi-tk'
TkMessage.new(:text => <<EOM).pack
This is a sample of the safe-Tk slave interpreter. \
-On the slave interpreter, 'tkoptdb.rb' demo is running.
-( Attention:: a safe-Tk interpreter can't read options \
+On the slave interpreter, 'tkoptdb.rb' demo is running.
+( NOTE:: a safe-Tk interpreter can't read options \
from a file. Options are given by the master interpreter \
in this script. )
The window shown this message is a root widget of \
the default master interpreter. The other window \
is a toplevel widget of the master interpreter, and it \
-has a container frame of the safe-Tk slave interpreter. \
-You can delete the slave by the button on the toplevel widget.
+has a container frame of the safe-Tk slave interpreter.
+'exit' on the slave interpreter exits the slave only. \
+You can also delete the slave by the button on the toplevel widget.
EOM
if ENV['LANG'] =~ /^ja/
@@ -33,21 +34,27 @@ ip = MultiTkIp.new_safeTk{
ent.each{|pat, val| Tk.tk_call('option', 'add', pat, val)}
}
-=begin
-ip.eval_proc{
+print "ip.eval_proc{$SAFE} ==> ", ip.eval_proc{$SAFE}, "\n"
+
+ret = ip.eval_proc{
# When a block is given to 'eval_proc' method,
# the block is evaluated on the IP's current safe level.
- # So, the followings raises exceptions.
+ # So, the followings raises an exception.
+ # An Exception object of the exception is returned as a
+ # return value of this method.
+
load file
}
-=end
+print "ip.eval_proc{}, which includes insecure operiation in the given block, returns an exception object: ", ret.inspect, "\n"
+
+print "If a proc object is given, the proc is evaluated on the safe-level which is kept on the proc :: ip.eval_proc( proc{$SAFE} ) ==> ", ip.eval_proc(proc{$SAFE}), "\n"
-ip.eval_proc(proc{
- # When a Procedure object is given to 'eval_proc' method as an argument,
- # the proc is evaluated on the proc's binding.
- # So, the followings are evaluated on $SAFE==0
+safe0_cmd = Proc.new{
+ # This proc object keeps current safe-level ($SAFE==0).
load file
-})
+}
+ip.eval_proc(safe0_cmd)
+
# Tk.mainloop is ignored on the slave-IP