Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5585 for data/media/tcl


Ignore:
Timestamp:
Jul 25, 2009, 9:47:30 PM (15 years ago)
Author:
landauf
Message:

experimenting with while and for in tcl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • data/media/tcl/init.tcl

    r5584 r5585  
    4848proc crossexecute {id args} {
    4949    return -code error "Can't execute a command now"
     50}
     51
     52
     53# running --
     54# Returns true if the interpreter is still suposed to be running
     55# This dummy procedure will be changed to it's real implementation by Orxonox itself.
     56
     57proc running {} {
     58    return 1
     59}
     60
     61
     62# orxonox::while --
     63# Works like while but breaks the loop if orxonox::running returns false
     64
     65proc ::orxonox::while {condition body} {
     66    set condition_cmd [list expr $condition]
     67    ::tcl::while {1} {
     68        if {![uplevel 1 $condition_cmd] || ![::running]} {
     69            break
     70        }
     71        uplevel 1 $body
     72    }
     73}
     74
     75
     76# orxonox::for --
     77# Works like for but breaks the loop if orxonox::running returns false
     78
     79proc ::orxonox::for {start condition step body} {
     80    set condition_cmd [list expr $condition]
     81    uplevel 1 $start
     82    ::tcl::while {1} {
     83        if {![uplevel 1 $condition_cmd] || ![::running]} {
     84            break
     85        }
     86        uplevel 1 $body
     87        uplevel 1 $step
     88    }
    5089}
    5190
     
    64103
    65104cd $::orxonox::mediapath
    66 
    67 
    68 # change the source command to use files from the media path
    69 
    70 #if {[llength [info command ::tcl::source]] == 0} {
    71 #    rename source ::tcl::source
    72 #}
    73 #proc source args {
    74 #    global ::orxonox::mediapath
    75 #
    76 #    set argc [llength $args]
    77 #    if {$argc != 1 && $argc != 3} {
    78 #        error "wrong # args: should be \"source ?-encoding name? fileName\""
    79 #    }
    80 #    if {$argc == 3} {
    81 #        if {[lindex $args 0] != "-encoding"} {
    82 #            error "bad option \"[lindex $args 0]\": must be -encoding"
    83 #        } else {
    84 #            set file [lindex $args 2]
    85 #        }
    86 #    } else {
    87 #        set file [lindex $args 0]
    88 #    }
    89 #    set orxonoxfile [file join $::orxonox::mediapath $file]
    90 #    if {[file readable $orxonoxfile]} {
    91 #        if {$argc == 1} {
    92 #            return [::tcl::source $orxonoxfile]
    93 #        } else {
    94 #            return [::tcl::source [lindex $args 0] [lindex $args 1] $orxonoxfile]
    95 #        }
    96 #    } else {
    97 #        return [::tcl::source $args]
    98 #    }
    99 #}
    100105
    101106
     
    182187            global ::orxonox::errormessage_unknown ::orxonox::errormessage_unknown_length
    183188
     189tcl::puts "unknown: $args"
    184190            set errorcode [catch {::tcl::unknown $args} result options]
    185191            set resultlist [split $result]
    186192            set success 1
    187 
     193tcl::puts "errorcode: $errorcode resultlist: $resultlist"
    188194            if {$errorcode && [llength $resultlist] >= $::orxonox::errormessage_unknown_length} {
    189195                for {set i 0} {$i < $::orxonox::errormessage_unknown_length} {incr i} {
    190196                    if {[lindex $::orxonox::errormessage_unknown $i] != [lindex $resultlist $i]} {
    191197                        set success 0
    192                         tcl::puts "not equal"
    193198                        break
    194199                    }
    195200                }
    196201            }
    197 
     202tcl::puts "success: $success"
    198203            if {!$success} {
    199204                return -code $errorcode -options $options $result
Note: See TracChangeset for help on using the changeset viewer.