Updated Branches:
  refs/heads/master e0a70faa0 -> c123ce075

Added a routine to handle ruby arrays.


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

Branch: refs/heads/master
Commit: c123ce075e001c649e46995da86e8a7d1c399fb7
Parents: e0a70fa
Author: Logan Bell <[email protected]>
Authored: Tue Oct 30 22:34:28 2012 -0700
Committer: Logan Bell <[email protected]>
Committed: Tue Oct 30 22:34:28 2012 -0700

----------------------------------------------------------------------
 clownfish/runtime/ruby/ext/Bind.c |   27 +++++++++++++++++++++++++++
 clownfish/runtime/ruby/ext/Bind.h |    1 +
 2 files changed, 28 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/c123ce07/clownfish/runtime/ruby/ext/Bind.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/ruby/ext/Bind.c 
b/clownfish/runtime/ruby/ext/Bind.c
index 50cb831..7d9cb5f 100644
--- a/clownfish/runtime/ruby/ext/Bind.c
+++ b/clownfish/runtime/ruby/ext/Bind.c
@@ -24,6 +24,9 @@ Bind_cfish_to_ruby(cfish_Obj *obj) {
   if (Cfish_Obj_Is_A(obj, CFISH_CHARBUF)) {
       return Bind_cb_to_ruby((cfish_CharBuf*)obj);
   }
+  else if (Cfish_Obj_Is_A(obj, CFISH_VARRAY)) {
+      return S_cfish_array_to_ruby_array((cfish_VArray*)obj);
+  }
 }
 
 VALUE
@@ -35,3 +38,27 @@ Bind_cb_to_ruby(const cfish_CharBuf *cb) {
         return rb_str_new((char*)Cfish_CB_Get_Ptr8(cb), Cfish_CB_Get_Size(cb));
     }
 }
+
+static VALUE
+S_cfish_array_to_ruby_array(cfish_VArray *varray) {
+    uint32_t num_elems = Cfish_VA_Get_Size(varray);
+
+    VALUE ruby_array = rb_ary_new2(num_elems - 1);
+
+    if (num_elems) {
+        //TODO Need to determine why c99 mode is not being honored
+        uint32_t i;
+        for (i = 0; i < num_elems; i++) {
+            cfish_Obj *val = Cfish_VA_Fetch(varray, i);
+            if (val == NULL) {
+                continue;
+            }
+            else {
+                // Recurse for each value.
+                VALUE const val_ruby = Bind_cfish_to_ruby(val);
+                rb_ary_store(ruby_array, i, val_ruby);
+            }
+        }
+    }
+    return ruby_array;
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/c123ce07/clownfish/runtime/ruby/ext/Bind.h
----------------------------------------------------------------------
diff --git a/clownfish/runtime/ruby/ext/Bind.h 
b/clownfish/runtime/ruby/ext/Bind.h
index e16cf54..ee7a05a 100644
--- a/clownfish/runtime/ruby/ext/Bind.h
+++ b/clownfish/runtime/ruby/ext/Bind.h
@@ -36,6 +36,7 @@ extern "C" {
 
 VALUE Bind_cfish_to_ruby(cfish_Obj *obj);
 VALUE Bind_cb_to_ruby(const cfish_CharBuf *cb);
+static VALUE S_cfish_array_to_ruby_array(cfish_VArray *varray);
 
 #ifdef __cplusplus
 }

Reply via email to