If you knew the representation of the function, and how captured variables
were stored in this representation, you could use unsafe to reinterpret the
function value as a usable form (pointer, tuple, whatever) and de-reference
this data to read captured variable addresses. In the case you describe,
Thanks Josh. Yes, a single-method interface can do the job. I just want to
know the unsafe way for curiosity. could you please explain more?
2017-11-22 22:12 GMT+08:00 Josh Humphries :
> The reflection package provides no way to do this. Even if it were
> possible to do with unsafe (not even sure
The reflection package provides no way to do this. Even if it were possible
to do with unsafe (not even sure it is, but maybe?), it would be brittle
and tied to an undocumented representation of a function and its captured
variables.
Instead, use a single-method interface. It's easy to create a fa
Hi, all
I known that method of a struct can be a function with explicit receiver,
like this
type Param struct {
v int
}
func (this *Param) Call() {
println(this.v)
}
p := &Param{v:10}
t := p.Call
t()
I wonder how can I get the receiver p from function t through
reflect. Thanks all.
--