Make CFCGoClass available via CFC Go bindings.

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

Branch: refs/heads/master
Commit: b69087b548b46160a3ccd876fdf8ad11d8329dc2
Parents: 160d20e
Author: Marvin Humphrey <[email protected]>
Authored: Sun Apr 12 09:07:54 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Wed May 6 14:28:16 2015 -0700

----------------------------------------------------------------------
 compiler/go/cfc/cfc.go | 37 +++++++++++++++++++++++++++++++++++++
 compiler/include/CFC.h |  1 +
 2 files changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b69087b5/compiler/go/cfc/cfc.go
----------------------------------------------------------------------
diff --git a/compiler/go/cfc/cfc.go b/compiler/go/cfc/cfc.go
index a47f85f..8d09880 100644
--- a/compiler/go/cfc/cfc.go
+++ b/compiler/go/cfc/cfc.go
@@ -87,6 +87,10 @@ type BindGo struct {
        ref *C.CFCGo
 }
 
+type BindGoClass struct {
+       ref *C.CFCGoClass
+}
+
 func FetchParcel(name string) *Parcel {
        nameC := C.CString(name)
        defer C.free(unsafe.Pointer(nameC))
@@ -229,3 +233,36 @@ func RegisterParcelPackage(parcel, goPackage string) {
        defer C.free(unsafe.Pointer(goPackageC))
        C.CFCGo_register_parcel_package(parcelC, goPackageC)
 }
+
+func NewGoClass(parcel *Parcel, className string) *BindGoClass {
+       classNameC := C.CString(className)
+       defer C.free(unsafe.Pointer(classNameC))
+       obj := C.CFCGoClass_new(parcel.ref, classNameC)
+       return wrapBindGoClass(unsafe.Pointer(obj))
+}
+
+func GoClassSingleton(className string) *BindGoClass {
+       classNameC := C.CString(className)
+       defer C.free(unsafe.Pointer(classNameC))
+       singletonC := C.CFCGoClass_singleton(classNameC)
+       if singletonC == nil {
+               return nil
+       }
+       C.CFCBase_incref((*C.CFCBase)(unsafe.Pointer(singletonC)))
+       return wrapBindGoClass(unsafe.Pointer(singletonC))
+}
+
+func wrapBindGoClass(ptr unsafe.Pointer) *BindGoClass {
+       obj := &BindGoClass{(*C.CFCGoClass)(ptr)}
+       runtime.SetFinalizer(obj, (*BindGoClass).finalize)
+       return obj
+}
+
+
+func (obj *BindGoClass) finalize() {
+       C.CFCBase_decref((*C.CFCBase)(unsafe.Pointer(obj.ref)))
+}
+
+func (obj *BindGoClass) Register() {
+       C.CFCGoClass_register(obj.ref)
+}

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b69087b5/compiler/include/CFC.h
----------------------------------------------------------------------
diff --git a/compiler/include/CFC.h b/compiler/include/CFC.h
index 2cc85f4..0e76090 100644
--- a/compiler/include/CFC.h
+++ b/compiler/include/CFC.h
@@ -44,6 +44,7 @@
 #include "CFCBindMethod.h"
 
 #include "CFCGo.h"
+#include "CFCGoClass.h"
 
 #include "CFCPerl.h"
 #include "CFCPerlSub.h"

Reply via email to