Permalink
Browse files

Interp#to_tcl does not include builtin variables and procedures

  • Loading branch information...
1 parent f6bec4a commit 2918eaf7e32ceedcf423a66e9a726ae0936bdbca @sstephenson sstephenson committed Nov 7, 2008
Showing with 23 additions and 4 deletions.
  1. +1 −1 TODO
  2. +2 −1 lib/tcl/interp.rb
  3. +10 −0 lib/tcl/proc.rb
  4. +9 −0 lib/tcl/var.rb
  5. +1 −2 test/interp_test.rb
View
2 TODO
@@ -1,2 +1,2 @@
+* Tcl::Proc#builtin? should return false if the procedure has been overridden
* Tcl::Interp#to_tcl should account for interpreter aliases (see http://wiki.tcl.tk/8766) and namespaces.
-
View
@@ -41,7 +41,8 @@ def vars
def to_tcl
%w( var proc ).inject([]) do |lines, type|
send("#{type}s").sort.each do |name|
- lines << send(type, name).to_tcl
+ object = send(type, name)
+ lines << object.to_tcl unless object.builtin?
end
lines
end.join("\n")
View
@@ -1,5 +1,10 @@
module Tcl
class Proc
+ BUILTINS = %w(
+ auto_execok auto_import auto_load auto_load_index
+ auto_qualify tclLog unknown
+ )
+
include InterpHelper
attr_reader :name
@@ -36,5 +41,10 @@ def call(*args)
def to_tcl
_(:proc, name, _(*arguments), body)
end
+
+ def builtin?
+ # TODO should also check to see if the definition has changed
+ BUILTINS.include?(name)
+ end
end
end
View
@@ -1,5 +1,10 @@
module Tcl
class Var
+ BUILTINS = %w(
+ auto_index auto_oldpath auto_path env errorCode errorInfo
+ tcl_libPath tcl_library tcl_patchLevel tcl_pkgPath tcl_platform tcl_version
+ )
+
include InterpHelper
class << self
@@ -21,6 +26,10 @@ def initialize(interp, name)
@name = name.to_s
to_tcl
end
+
+ def builtin?
+ BUILTINS.include?(name)
+ end
end
class StringVar < Var
View
@@ -91,7 +91,6 @@ def test_var
end
def test_to_tcl
- @interp.clear!
@interp.eval IO.read(path_to_fixture("test.tcl"))
assert_equal <<-EOF.chomp, @interp.to_tcl
set a 0
@@ -101,7 +100,7 @@ def test_to_tcl
proc e {} {}
EOF
end
-
+
def test_interp_helper_method_missing_super_passthrough
assert_raises(NoMethodError) { @interp.nonexistent }
end

0 comments on commit 2918eaf

Please sign in to comment.