From: Matt S Trout Date: Sat, 4 Aug 2012 16:09:07 +0000 (+0000) Subject: json.tcl first attempt at connection code X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1a2f3e8bb2fe99dc014aa55ceb9e1ac68296d6af;p=scpubgit%2FTenDotTcl.git json.tcl first attempt at connection code --- diff --git a/json.tcl b/json.tcl index 7503515..1acd13f 100644 --- a/json.tcl +++ b/json.tcl @@ -32,6 +32,13 @@ namespace eval ten::json { return $num } + proc decomma {str} { + switch [string index $str end] { + , { string range $str 0 end-1 } + default { return $str } + } + } + proc list {args} { variable indent variable nl @@ -41,6 +48,7 @@ namespace eval ten::json { append out $nl$indent append out [ deparse $el ], } + set out [ decomma $out ] outdent_one append out $nl$indent\] return $out @@ -54,6 +62,7 @@ namespace eval ten::json { dict for {k v} $args { append out $nl$indent[ str $k ]:\ [ deparse $v ], } + set out [ decomma $out ] outdent_one append out $nl$indent\} } @@ -240,6 +249,36 @@ set jtext { ] } +namespace eval ten::connection { + + proc receive_data_for {name} { + + + proc conn_setup {name input output initial_handlers} { + variable "${name}_input" $input + variable "${name}_input_closed" "" + variable "${name}_output" $output + variable "${name}_handlers" + array set "${name}_handlers" $initial_handlers + fileevent $input readable [list receive_data_for $name] + puts $output Shere + } + + proc run_until_close {name} { + vwait "${name}_input_closed" + set close_value "\$${name}_input_closed" + teardown $name + return $close_value + } + + proc teardown {name} { + close [ expr "\$${name}_output" ] + unset "${name}_input" + unset "${name}_input_closed" + unset "${name}_output" + unset "${name}_handlers" + } + namespace import ten::json::* puts [ deparse_json $ex_json 2 ]