Пример #1
0
//export gGoclosureFinalizeGo
func gGoclosureFinalizeGo(goclosure_up unsafe.Pointer) {
	goclosure := (*C.GGoClosure)(goclosure_up)
	clo := *(*interface{})(C.gGoclosureGetFunc(goclosure))
	recv := *(*interface{})(C.gGoclosureGetRecv(goclosure))
	Holder.Release(clo)
	Holder.Release(recv)
}
Пример #2
0
//export gGoclosureMarshalGo
func gGoclosureMarshalGo(goclosure_up, ret_up unsafe.Pointer, nargs int32, args_up unsafe.Pointer) {
	var callargs [20]reflect.Value
	var recv reflect.Value
	goclosure := (*C.GGoClosure)(goclosure_up)
	ret := (*Value)(ret_up)
	args := (*(*[alot]Value)(args_up))[:nargs]
	f := reflect.ValueOf(*(*interface{})(C.gGoclosureGetFunc(goclosure)))
	ft := f.Type()
	callargsn := ft.NumIn()

	recvi := *(*interface{})(C.gGoclosureGetRecv(goclosure))
	if recvi != nil {
		recv = reflect.ValueOf(recvi)
	}

	if callargsn >= 20 {
		panic("too many arguments in a closure")
	}

	for i, n := 0, callargsn; i < n; i++ {
		idx := i
		if recvi != nil {
			idx--
			if i == 0 {
				callargs[i] = recv
				continue
			}
		}

		in := ft.In(i)

		// use default value, if there is not enough args
		if len(args) <= idx {
			callargs[i] = reflect.New(in).Elem()
			continue
		}

		v := args[idx].GetGoValue(in)
		callargs[i] = v
	}

	out := f.Call(callargs[:callargsn])
	if len(out) == 1 {
		ret.SetGoValue(out[0])
	}
}