Fix invocation of closure from runtime
This commit is contained in:
28
_test/server6.go
Normal file
28
_test/server6.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("hello world"))
|
||||
})
|
||||
|
||||
type T1 struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (t *T1) Handler(h http.Handler) http.Handler {
|
||||
fmt.Println("#1", t.Name)
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("#2", t.Name)
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
t := &T1{"myName"}
|
||||
handler := t.Handler(myHandler)
|
||||
http.ListenAndServe(":8080", handler)
|
||||
}
|
||||
@@ -340,7 +340,6 @@ func (interp *Interpreter) Cfg(root *Node, sdef *NodeMap) []*Node {
|
||||
for i, c := range n.child[1:] {
|
||||
// Wrap function defintion so it can be called from runtime
|
||||
if c.kind == FuncLit {
|
||||
log.Println(n.index, "FuncLit")
|
||||
n.child[1+i].rval = reflect.MakeFunc(rtype.In(i), c.wrapNode)
|
||||
n.child[1+i].kind = Rvalue
|
||||
} else if c.ident == "nil" {
|
||||
|
||||
@@ -498,7 +498,7 @@ func getFunc(n *Node, f *Frame) {
|
||||
frame := *f
|
||||
node.frame = &frame
|
||||
f.data[n.findex] = &node
|
||||
|
||||
n.interp.Frame = &frame // Temporary, store context for futur call from runtime
|
||||
}
|
||||
|
||||
func getMap(n *Node, f *Frame) {
|
||||
|
||||
Reference in New Issue
Block a user