Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a console script

git-svn-id: svn://rubyforge.org/var/svn/tcl/trunk@3 017b7ecb-b1d0-4998-98d6-e9014aaf4887
  • Loading branch information...
commit b78464a0c808e03ed7e65fdc4fdac8fc962dbc58 1 parent 4d42a87
Sam Stephenson sstephenson authored
Showing with 31 additions and 0 deletions.
  1. +31 −0 script/console
31 script/console
View
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+require File.join(File.dirname(__FILE__), *%w".. lib tcl")
+
+filename = ARGV.shift || File.join(File.dirname(__FILE__), *%w".. .state.dat")
+interp = Tcl::Interp.load_from_file(filename) rescue Tcl::Interp.new
+script = ""
+
+at_exit do
+ # FIXME This is not fired when you call "exit" from Tcl
+ File.open(filename, "w") do |file|
+ file.write(interp.to_tcl)
+ end
+end
+
+print ">> "
+$stdin.each_line do |line|
+ script << line
+ if interp.list_to_array(script)
+ begin
+ result = interp.eval(script)
+ puts result unless result.length.zero?
+ rescue Tcl::Error => e
+ puts e
+ end
+ script = ""
+ print ">> "
+ else
+ print "?> "
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.