From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/ext/tk/sample/tkoptdb-safeTk.rb | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 jni/ruby/ext/tk/sample/tkoptdb-safeTk.rb (limited to 'jni/ruby/ext/tk/sample/tkoptdb-safeTk.rb') diff --git a/jni/ruby/ext/tk/sample/tkoptdb-safeTk.rb b/jni/ruby/ext/tk/sample/tkoptdb-safeTk.rb new file mode 100644 index 0000000..7502e30 --- /dev/null +++ b/jni/ruby/ext/tk/sample/tkoptdb-safeTk.rb @@ -0,0 +1,73 @@ +#!/usr/bin/env ruby + +require 'multi-tk' + +TkMessage.new(:text => < ", ip.eval_proc{$SAFE}, "\n" + +print "\ncall 'ip.wait_on_mainloop = false'\n" +print "If 'ip.wait_on_mainloop? == true', ", + "when 'mainloop' is called on 'ip.eval_proc', ", + "'ip.eval_proc' does't return while the root window exists.\n", + "If you want to avoid that, set wait_on_mainloop to false. ", + "Then the mainloop in the eval_proc returns soon ", + "and the following steps are evaluated. \n", + "If you hate the both of them, use 'ip.bg_eval_proc' or ", + "wrap 'ip.eval_proc' by a thread.\n" + +ip.wait_on_mainloop = false + +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 an exception. + # An Exception object of the exception is returned as a + # return value of this method. + + load file +} +print "\nip.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" + +safe0_cmd = Proc.new{ + print 'safe0_cmd safe-level == ', $SAFE, "\n" + # This proc object keeps current safe-level ($SAFE==0). + load file +} +ip.eval_proc{safe0_cmd.call} + +# Tk.mainloop is ignored on the slave-IP +Tk.mainloop -- cgit v1.2.3