I32Array Go ctor binding.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/2b8b6323 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/2b8b6323 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/2b8b6323 Branch: refs/heads/master Commit: 2b8b63236b2854b344cdba725f7ac6b60d844644 Parents: 456a825 Author: Marvin Humphrey <[email protected]> Authored: Wed Aug 12 16:58:06 2015 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Wed Sep 9 18:25:23 2015 -0700 ---------------------------------------------------------------------- go/lucy/object.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/2b8b6323/go/lucy/object.go ---------------------------------------------------------------------- diff --git a/go/lucy/object.go b/go/lucy/object.go index 0dc669f..78c86f5 100644 --- a/go/lucy/object.go +++ b/go/lucy/object.go @@ -18,11 +18,13 @@ package lucy /* #include "Lucy/Object/BitVector.h" +#include "Lucy/Object/I32Array.h" */ import "C" import "fmt" +import "unsafe" -import _ "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish" +import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish" func (bv *BitVectorIMP) ToArray() []bool { cap := bv.GetCapacity() @@ -36,3 +38,14 @@ func (bv *BitVectorIMP) ToArray() []bool { return bools } +func NewI32Array(nums []int32) I32Array { + size := len(nums) + if int(C.uint32_t(size)) != size { + panic(clownfish.NewErr("input too large")) + } + obj := C.lucy_I32Arr_new_blank(C.uint32_t(size)) + for i := 0; i < size; i++ { + C.LUCY_I32Arr_Set(obj, C.uint32_t(i), C.int32_t(nums[i])) + } + return WRAPI32Array(unsafe.Pointer(obj)) +}
