Incr Tcl
如果在不使用的情况下调用类的嵌套方法,则$this
在协程中失败并出现错误
cannot yield: C stack busy
$this
但是通过工程调用相同的方法。为什么?有什么不同?因为它在没有协程的情况下双向工作。
package require Itcl
itcl::class A {
method internal {} {
puts "internal"
if {[info coroutine] !=""} yield
}
method external {f} {
puts "external $f"
switch $f {
use_this { $this internal ;# this works with coroutine }
without_this { internal ;# but this does not }
}
}
method outer {f args} {
puts "outer $f $args"
switch $f {
coroutine { coroutine co $this {*}$args }
direct { {*}$args }
}
puts "-----"
}
}
A a
a outer direct internal
a outer direct external use_this
a outer direct external without_this
a outer coroutine internal
a outer coroutine external use_this
a outer coroutine external without_this ;# <-- ERROR: cannot yield: C stack busy