Version 0 of interp serialize

Updated 2006-07-19 05:32:26

Wed Jul 19, CMcC A quickie to serialise the variables in a sub interpreter.

    proc nstree {interp {prefix ""}} {
        set result {}
        foreach ns [$interp eval namespace children $prefix] {
            lappend result $ns
            lappend result {expand}[nstree $interp $ns]
        }
        return $result
    }

    proc serialize {interp} {
        $interp eval {unset -nocomplain errorCode; unset -nocomplain errorInfo}
        set result {}
        foreach v [$interp eval info globals] {
            if {[string match tcl* $v]} continue
            if {[$interp eval array exists $v]} {
                lappend result "array set $v [list [$interp eval array get $v]]"
            } else {
                lappend result "set $v [list [$interp eval set $v]]"
            }
        }

        foreach ns [nstree $interp] {
            foreach v [$interp eval info vars ${ns}::*] {
                if {[array exists $v]} {
                    lappend result "array set $v [list [$interp eval array get $v]]"
                } else {
                    lappend result "set $v [list [$interp eval set $v]]"
                }
            }
        }
        return [join $result "; "]
    }