summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk
diff options
context:
space:
mode:
Diffstat (limited to 'ext/tk/lib/tk')
-rw-r--r--ext/tk/lib/tk/namespace.rb48
1 files changed, 45 insertions, 3 deletions
diff --git a/ext/tk/lib/tk/namespace.rb b/ext/tk/lib/tk/namespace.rb
index 7634527724..35ea7a6b95 100644
--- a/ext/tk/lib/tk/namespace.rb
+++ b/ext/tk/lib/tk/namespace.rb
@@ -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))