Beispiel #1
0
func RegisterNative(className string, method string, paramTypes []string, returnType string, fn interface{}) {
	f := func(t string) types.Typed {
		switch t {
		case "void":
			return types.Basic(types.VoidKind)
		case "int":
			return types.Basic(types.IntKind)
		case "long":
			return types.Basic(types.LongKind)
		case "float":
			return types.Basic(types.FloatKind)
		case "double":
			return types.Basic(types.DoubleKind)
		case "boolean":
			return types.Basic(types.BoolKind)
		default:
			return types.Class{types.NewName(t)}
		}
		return types.Basic(types.VoidKind)
	}

	var msig types.MethodSignature
	for _, v := range paramTypes {
		msig.Params = append(msig.Params, f(v))
	}
	msig.Return = f(returnType)

	GetEnv().RegisterNative(className, method, msig, fn)
}