From af41a0c14673ce3cfcea1cc6509024401f695dbc Mon Sep 17 00:00:00 2001 From: ocean Date: Wed, 3 Aug 2005 13:10:48 +0000 Subject: * ext/tk/lib/tk/variable.rb: TkVariable#trace didn't work on TkVariable retrived from TkVariable.new_hash.ref. [ruby-dev:26721] (written by Hidetoshi NAGAI) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tk/variable.rb | 91 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 25 deletions(-) (limited to 'ext/tk/lib/tk') diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb index 33cf603a92..397489d982 100644 --- a/ext/tk/lib/tk/variable.rb +++ b/ext/tk/lib/tk/variable.rb @@ -41,13 +41,13 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') EOL #def TkVariable.callback(args) - def TkVariable.callback(name1, name2, op) + def TkVariable.callback(id, name1, name2, op) #name1,name2,op = tk_split_list(args) #name1,name2,op = tk_split_simplelist(args) - if TkVar_CB_TBL[name1] + if TkVar_CB_TBL[id] #_get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op)) begin - _get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2, op)) + _get_eval_string(TkVar_CB_TBL[id].trace_callback(name2, op)) rescue SystemExit exit(0) rescue Interrupt @@ -270,6 +270,9 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') Tk_VARIABLE_ID[1].succ! TkVar_ID_TBL[@id] = self + @var = @id + @elem = nil + @def_default = false @default_val = nil @@ -805,6 +808,7 @@ end end def variable + # keeps a Tcl's variable name TkVarAccess.new(self._value) end def variable_element(*idxs) @@ -1264,12 +1268,14 @@ end def trace(opts, cmd = Proc.new) @trace_var = [] if @trace_var == nil #opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') - opts = ['r','w','u'].find_all{|c| opts.to_s.index(c)}.join('') + opts = opts.to_s + opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') @trace_var.unshift([opts,cmd]) if @trace_opts == nil TkVar_CB_TBL[@id] = self @trace_opts = opts.dup - Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, + 'rb_var ' << @id) =begin if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION # TCL_VERSION >= 8.4 @@ -1285,9 +1291,11 @@ end #opts.each_byte{|c| newopts += c.chr unless newopts.index(c)} opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)} if newopts != @trace_opts - Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, + 'rb_var ' << @id) @trace_opts.replace(newopts) - Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, + 'rb_var ' << @id) =begin if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION # TCL_VERSION >= 8.4 @@ -1311,15 +1319,20 @@ end end def trace_element(elem, opts, cmd = Proc.new) + if @elem + fail(RuntimeError, + "invalid for a TkVariable which denotes an element of Tcl's array") + end @trace_elem = {} if @trace_elem == nil @trace_elem[elem] = [] if @trace_elem[elem] == nil - #opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') - opts = ['r','w','u'].find_all{|c| opts.to_s.index(c)}.join('') + opts = opts.to_s + opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') @trace_elem[elem].unshift([opts,cmd]) if @trace_opts == nil TkVar_CB_TBL[@id] = self @trace_opts = opts.dup - Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, + 'rb_var ' << @id) =begin if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION # TCL_VERSION >= 8.4 @@ -1336,9 +1349,11 @@ end # opts.each_byte{|c| newopts += c.chr unless newopts.index(c)} opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)} if newopts != @trace_opts - Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, + 'rb_var ' << @id) @trace_opts.replace(newopts) - Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, + 'rb_var ' << @id) =begin if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION # TCL_VERSION >= 8.4 @@ -1365,7 +1380,12 @@ end return [] unless @trace_var @trace_var.dup end - def trace_vinfo_for_element(elem) + + def _trace_vinfo_for_element(elem) + if @elem + fail(RuntimeError, + "invalid for a TkVariable which denotes an element of Tcl's array") + end return [] unless @trace_elem return [] unless @trace_elem[elem] @trace_elem[elem].dup @@ -1373,8 +1393,8 @@ end def trace_vdelete(opts,cmd) return self unless @trace_var.kind_of? Array - #opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') - opts = ['r','w','u'].find_all{|c| opts.to_s.index(c)}.join('') + opts = opts.to_s + opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') idx = -1 newopts = '' @trace_var.each_with_index{|e,i| @@ -1398,10 +1418,11 @@ end } } - #newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('') - newopts = ['r','w','u'].find_all{|c| newopts.to_s.index(c)}.join('') + newopts = newopts.to_s + newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('') if newopts != @trace_opts - Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, + 'rb_var ' << @id) =begin if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION # TCL_VERSION >= 8.4 @@ -1415,7 +1436,8 @@ end =end @trace_opts.replace(newopts) if @trace_opts != '' - Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, + 'rb_var ' << @id) =begin if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION # TCL_VERSION >= 8.4 @@ -1434,10 +1456,14 @@ end end def trace_vdelete_for_element(elem,opts,cmd) + if @elem + fail(RuntimeError, + "invalid for a TkVariable which denotes an element of Tcl's array") + end return self unless @trace_elem.kind_of? Hash return self unless @trace_elem[elem].kind_of? Array - # opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') - opts = ['r','w','u'].find_all{|c| opts.to_s.index(c)}.join('') + opts = opts.to_s + opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') idx = -1 @trace_elem[elem].each_with_index{|e,i| if idx < 0 && e[0] == opts && e[1] == cmd @@ -1463,10 +1489,11 @@ end } } - #newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('') - newopts = ['r','w','u'].find_all{|c| newopts.to_s.index(c)}.join('') + newopts = newopts.to_s + newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('') if newopts != @trace_opts - Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts, + 'rb_var ' << @id) =begin if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION # TCL_VERSION >= 8.4 @@ -1480,7 +1507,8 @@ end =end @trace_opts.replace(newopts) if @trace_opts != '' - Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var') + Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, + 'rb_var ' << @id) =begin if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION # TCL_VERSION >= 8.4 @@ -1519,6 +1547,9 @@ class TkVarAccess var == $1, elem == $2 + @var = $1 + @elem = $2 + end + # teach Tk-ip that @id is global var + INTERP._invoke_without_enc('global', @var) +=begin begin INTERP._invoke_without_enc('global', @id) rescue => e @@ -1541,6 +1581,7 @@ class TkVarAccess