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: add MultiTkIp#eval and bg_eval.

* ext/tk/lib/tk/namespace.rb: TkNamespace#eval was enbugged at the
  last commit. Now it will return a proper object.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2006-01-31 03:01:31 +00:00
parent 09d952c543
commit 598451429c
3 changed files with 114 additions and 4 deletions

View file

@ -1,3 +1,10 @@
Tue Jan 31 11:58:51 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: add MultiTkIp#eval and bg_eval.
* ext/tk/lib/tk/namespace.rb: TkNamespace#eval was enbugged at the
last commit. Now it will return a proper object.
Tue Jan 31 00:08:22 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/syck/rubyext.c (syck_resolver_transfer): workaround for SEGV.

View file

@ -1702,6 +1702,35 @@ class MultiTkIp
alias background_eval_string bg_eval_string
alias bg_eval_str bg_eval_string
alias background_eval_str bg_eval_string
def eval(*args, &blk)
if block_given?
eval_proc(*args, &blk)
elsif args[0]
if args[0].respond_to?(:call)
eval_proc(*args)
else
eval_string(*args)
end
else
fail ArgumentError, "no argument to eval"
end
end
def bg_eval(*args, &blk)
if block_given?
bg_eval_proc(*args, &blk)
elsif args[0]
if args[0].respond_to?(:call)
bg_eval_proc(*args)
else
bg_eval_string(*args)
end
else
fail ArgumentError, "no argument to eval"
end
end
alias background_eval bg_eval
end
class << MultiTkIp
@ -1711,7 +1740,39 @@ class << MultiTkIp
__getip.eval_proc(*args, &blk)
end
alias call eval_proc
alias eval_string eval_proc
def bg_eval_proc(*args, &blk)
# class ==> interp object
__getip.bg_eval_proc(*args, &blk)
end
alias background_eval_proc bg_eval_proc
alias thread_eval_proc bg_eval_proc
alias bg_call bg_eval_proc
alias background_call bg_eval_proc
def eval_string(cmd, *eval_args)
# class ==> interp object
__getip.eval_string(cmd, *eval_args)
end
alias eval_str eval_string
def bg_eval_string(cmd, *eval_args)
# class ==> interp object
__getip.bg_eval_string(cmd, *eval_args)
end
alias background_eval_string bg_eval_string
alias bg_eval_str bg_eval_string
alias background_eval_str bg_eval_string
def eval(*args, &blk)
# class ==> interp object
__getip.eval(*args, &blk)
end
def bg_eval(*args, &blk)
# class ==> interp object
__getip.bg_eval(*args, &blk)
end
alias background_eval bg_eval
end

View file

@ -14,7 +14,12 @@ class TkNamespace < TkObject
Tk_Namespace_ID_TBL = TkCore::INTERP.create_table
Tk_Namespace_ID = ["ns".freeze, "00000".taint].freeze
TkCore::INTERP.init_ip_env{ Tk_Namespace_ID_TBL.clear }
Tk_NsCode_RetObjID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
Tk_Namespace_ID_TBL.clear
Tk_NsCode_RetObjID_TBL.clear
}
def TkNamespace.id2obj(id)
Tk_Namespace_ID_TBL[id]? Tk_Namespace_ID_TBL[id]: id
@ -152,8 +157,9 @@ class TkNamespace < TkObject
#####################################
class NsCode < TkObject
def initialize(scope)
def initialize(scope, use_obj_id = false)
@scope = scope + ' '
@use_obj_id = use_obj_id
end
def path
@scope
@ -162,7 +168,11 @@ class TkNamespace < TkObject
@scope
end
def call(*args)
TkCore::INTERP._eval_without_enc(@scope + array2tk_list(args))
ret = TkCore::INTERP._eval_without_enc(@scope + array2tk_list(args))
if @use_obj_id
ret = TkNamespace::Tk_NsCode_RetObjID_TBL.delete(ret.to_i)
end
ret
end
end
@ -264,6 +274,7 @@ class TkNamespace < TkObject
def self.code(script = Proc.new)
TkNamespace.new('').code(script)
end
=begin
def code(script = Proc.new)
if script.kind_of?(String)
cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(script)}
@ -275,6 +286,29 @@ class TkNamespace < TkObject
TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code',
_get_eval_string(cmd, false)))
end
=end
def code(script = Proc.new)
if script.kind_of?(String)
cmd = proc{|*args|
ret = ScopeArgs.new(@fullname,*args).instance_eval(script)
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
}
elsif script.kind_of?(Proc)
cmd = proc{|*args|
ret = ScopeArgs.new(@fullname,*args).instance_eval(&script)
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
}
else
fail ArgumentError, "String or Proc is expected"
end
TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code',
_get_eval_string(cmd, false)),
true)
end
def self.current_path
tk_call('namespace', 'current')
@ -339,6 +373,7 @@ class TkNamespace < TkObject
#tk_call('namespace', 'eval', namespace, cmd, *args)
TkNamespace.new(namespece).eval(cmd, *args)
end
=begin
def eval(cmd = Proc.new, *args)
#TkNamespace.eval(@fullname, cmd, *args)
#ns_tk_call(cmd, *args)
@ -348,6 +383,13 @@ class TkNamespace < TkObject
uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
tk_tcl2ruby(ret)
end
=end
def eval(cmd = Proc.new, *args)
code_obj = code(cmd)
ret = code_obj.call(*args)
uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
ret
end
def self.exist?(ns)
bool(tk_call('namespace', 'exists', ns))