Index: tcc4tcl.tcl ================================================================== --- tcc4tcl.tcl +++ tcc4tcl.tcl @@ -109,18 +109,18 @@ Log "INJECTING CCODE" append tcc(code) $code \n } + proc ::tcc4tcl::cc {code} { variable tcc if {![info exists tcc(cc)]} { set tcc(cc) [::tcc4tcl::new] } - Log code:$code $tcc(cc) compile $code } #----------------------------------------------------------- New DLL API namespace eval ::tcc4tcl::dll {} @@ -449,29 +449,39 @@ if {[info exists tcc(tk)] && $tcc(tk)} { append code "\#include " "\n" } - if {[info exists tcc(code)] && [string length $tcc(code)]>0} { + if {[info exists tcc(code)]} { append code $tcc(code) append code "\n" } + set tcc(code) "" append code "int $cname (ClientData $v(clientdata),Tcl_Interp *$v(interp)," append code "int $v(objc),Tcl_Obj *CONST $v(objv)\[\]) {" "\n" append code [lindex $args end] "\n" append code "}" "\n" - uplevel 1 [list tcc4tcl::cc $code] + if {[catch { + uplevel 1 [list tcc4tcl::cc $code] + } err]} { + unset tcc(cc) + tcc4tcl::reset + + return -code error $err + } Log "CREATING TCL COMMAND $procname / $cname" uplevel 1 [list $tcc(cc) command $procname $cname] + unset tcc(cc) ;# can't be used for compiling anymore + tcc4tcl::reset } proc ::tcc4tcl::tk {args} { variable tcc set tcc(tk) 1 } ::tcc4tcl::reset namespace eval tcc4tcl {namespace export cproc ccode cdata} Index: test ================================================================== --- test +++ test @@ -5,8 +5,17 @@ tcc4tcl::cproc test {int i} int { return(i+42); } tcc4tcl::cproc test1 {int i} int { return(i+42); } tcc4tcl::cproc ::bob::test1 {int i} int { return(i+42); } +# This will fail +catch { + tcc4tcl::cproc test2 {int i} int { badcode; } +} + +# This should work +tcc4tcl::cproc test3 {int i} int { return(i+42); } + puts [test 1] -puts [::test1 1] +puts [test1 1] +puts [test3 1] puts [::bob::test1 1]