Пример #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)
}
Пример #2
0
/* Helper function for the parameter-side only of a JavaMethodSignature.
the resultant string is () quoted by jms.ParameterString()
*/
func ParameterString(ctx *Environment, params ...interface{}) (s string, err error) {
	jms := types.MethodSignature{}
	jms.Params, err = ParameterTypes(ctx, params...)
	if err == nil {
		s = jms.ParameterString()
	}
	return
}
Пример #3
0
func (self *Environment) RegisterNative(className string, method string, sig types.MethodSignature, fptr interface{}) error {
	class, err := self.GetClass(types.NewName(className))
	if err != nil {
		return err
	}
	cname := C.CString(method)
	defer C.free(unsafe.Pointer(cname))

	csig := C.CString(sig.String())
	defer C.free(unsafe.Pointer(csig))
	C.envRegisterNative(self.env, class.class, cname, csig, fptr.(unsafe.Pointer))

	return nil
}