[Orxonox-commit 834] r2210 - media/tcl

landauf at orxonox.net landauf at orxonox.net
Sat Jul 25 21:47:30 CEST 2009


Author: landauf
Date: 2009-07-25 21:47:30 +0200 (Sat, 25 Jul 2009)
New Revision: 2210

Modified:
   media/tcl/init.tcl
Log:
experimenting with while and for in tcl

Modified: media/tcl/init.tcl
===================================================================
--- media/tcl/init.tcl	2009-07-24 15:56:47 UTC (rev 2209)
+++ media/tcl/init.tcl	2009-07-25 19:47:30 UTC (rev 2210)
@@ -50,6 +50,45 @@
 }
 
 
+# running --
+# Returns true if the interpreter is still suposed to be running
+# This dummy procedure will be changed to it's real implementation by Orxonox itself.
+
+proc running {} {
+    return 1
+}
+
+
+# orxonox::while --
+# Works like while but breaks the loop if orxonox::running returns false
+
+proc ::orxonox::while {condition body} {
+    set condition_cmd [list expr $condition]
+    ::tcl::while {1} {
+        if {![uplevel 1 $condition_cmd] || ![::running]} {
+            break
+        }
+        uplevel 1 $body
+    }
+}
+
+
+# orxonox::for --
+# Works like for but breaks the loop if orxonox::running returns false
+
+proc ::orxonox::for {start condition step body} {
+    set condition_cmd [list expr $condition]
+    uplevel 1 $start
+    ::tcl::while {1} {
+        if {![uplevel 1 $condition_cmd] || ![::running]} {
+            break
+        }
+        uplevel 1 $body
+        uplevel 1 $step
+    }
+}
+
+
 # add the path to this file to the auto path
 
 set filepath [info script]
@@ -65,40 +104,6 @@
 cd $::orxonox::mediapath
 
 
-# change the source command to use files from the media path
-
-#if {[llength [info command ::tcl::source]] == 0} {
-#    rename source ::tcl::source
-#}
-#proc source args {
-#    global ::orxonox::mediapath
-#
-#    set argc [llength $args]
-#    if {$argc != 1 && $argc != 3} {
-#        error "wrong # args: should be \"source ?-encoding name? fileName\""
-#    }
-#    if {$argc == 3} {
-#        if {[lindex $args 0] != "-encoding"} {
-#            error "bad option \"[lindex $args 0]\": must be -encoding"
-#        } else {
-#            set file [lindex $args 2]
-#        }
-#    } else {
-#        set file [lindex $args 0]
-#    }
-#    set orxonoxfile [file join $::orxonox::mediapath $file]
-#    if {[file readable $orxonoxfile]} {
-#        if {$argc == 1} {
-#            return [::tcl::source $orxonoxfile]
-#        } else {
-#            return [::tcl::source [lindex $args 0] [lindex $args 1] $orxonoxfile]
-#        }
-#    } else {
-#        return [::tcl::source $args]
-#    }
-#}
-
-
 # Redefines puts to write directly into the Orxonox console if the channel is stdout or stderr.
 
 if {[llength [info command ::tcl::puts]] == 0} {
@@ -181,20 +186,20 @@
         proc unknown args {
             global ::orxonox::errormessage_unknown ::orxonox::errormessage_unknown_length
 
+tcl::puts "unknown: $args"
             set errorcode [catch {::tcl::unknown $args} result options]
             set resultlist [split $result]
             set success 1
-
+tcl::puts "errorcode: $errorcode resultlist: $resultlist"
             if {$errorcode && [llength $resultlist] >= $::orxonox::errormessage_unknown_length} {
                 for {set i 0} {$i < $::orxonox::errormessage_unknown_length} {incr i} {
                     if {[lindex $::orxonox::errormessage_unknown $i] != [lindex $resultlist $i]} {
                         set success 0
-                        tcl::puts "not equal"
                         break
                     }
                 }
             }
-
+tcl::puts "success: $success"
             if {!$success} {
                 return -code $errorcode -options $options $result
             } else {




More information about the Orxonox-commit mailing list