Custom Go bindings for Class.

Add hand-coded binding for FetchClass.  Override GetMethods to return
`[]Method` rather than `[]interface{}`.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/9f8face6
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/9f8face6
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/9f8face6

Branch: refs/heads/master
Commit: 9f8face671530d662168a5482c5946397e5e7986
Parents: fe8d05a
Author: Marvin Humphrey <[email protected]>
Authored: Fri Aug 7 14:31:35 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Sun Aug 9 19:00:35 2015 -0700

----------------------------------------------------------------------
 runtime/go/build.go               |  4 ++++
 runtime/go/clownfish/clownfish.go | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9f8face6/runtime/go/build.go
----------------------------------------------------------------------
diff --git a/runtime/go/build.go b/runtime/go/build.go
index d7bb7a0..e509dba 100644
--- a/runtime/go/build.go
+++ b/runtime/go/build.go
@@ -144,6 +144,10 @@ func specMethods(parcel *cfc.Parcel) {
        errBinding.SpecMethod("", "Error() string")
        errBinding.Register()
 
+       classBinding := cfc.NewGoClass(parcel, "Clownfish::Class")
+       classBinding.SpecMethod("Get_Methods", "GetMethods() []Method")
+       classBinding.Register()
+
        stringBinding := cfc.NewGoClass(parcel, "Clownfish::String")
        stringBinding.SpecMethod("Code_Point_At", "CodePointAt(uintptr) rune")
        stringBinding.SpecMethod("Code_Point_From", "CodePointFrom(uintptr) 
rune")

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9f8face6/runtime/go/clownfish/clownfish.go
----------------------------------------------------------------------
diff --git a/runtime/go/clownfish/clownfish.go 
b/runtime/go/clownfish/clownfish.go
index 34b6f5f..f6dfb27 100644
--- a/runtime/go/clownfish/clownfish.go
+++ b/runtime/go/clownfish/clownfish.go
@@ -123,6 +123,25 @@ type ObjIMP struct {
        ref uintptr
 }
 
+func FetchClass(className string) Class {
+       nameCF := (*C.cfish_String)(GoToString(className))
+       defer C.cfish_decref(unsafe.Pointer(nameCF))
+       class := C.cfish_Class_fetch_class(nameCF)
+       return WRAPClass(unsafe.Pointer(class))
+}
+
+func (c *ClassIMP) GetMethods() []Method {
+       self := (*C.cfish_Class)(unsafe.Pointer(c.TOPTR()))
+       methsVec := C.CFISH_Class_Get_Methods(self)
+       size := C.CFISH_Vec_Get_Size(methsVec)
+       meths := make([]Method, 0, int(size))
+       for i := C.size_t(0); i < size; i++ {
+               meths = append(meths, 
WRAPMethod(unsafe.Pointer(C.CFISH_Vec_Fetch(methsVec, i))))
+       }
+       C.cfish_decref(unsafe.Pointer(methsVec))
+       return meths
+}
+
 func NewString(goString string) String {
        str := C.CString(goString)
        len := C.size_t(len(goString))

Reply via email to