Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

arrays move across

  • Loading branch information...
commit b42a853d10cfe374f8909d9035931159ee350d37 1 parent 071d44a
@tenderlove authored
Showing with 23 additions and 1 deletion.
  1. +14 −1 ext/phuby/phuby_conversions.c
  2. +9 −0 test/test_array.rb
View
15 ext/phuby/phuby_conversions.c
@@ -1,4 +1,4 @@
-#include <phuby_conversions.h>
+#include <phuby.h>
zval * Phuby_value_to_zval(VALUE rt, VALUE value)
{
@@ -32,6 +32,19 @@ zval * Phuby_value_to_zval(VALUE rt, VALUE value)
rb_hash_aset(map, INT2NUM((int)php_value), value);
}
break;
+ case T_ARRAY:
+ {
+ array_init(php_value);
+ int i;
+ for(i = 0; i < RARRAY_LEN(value); i++) {
+ VALUE key = rb_funcall(INT2NUM(i), rb_intern("to_s"), 0);
+ VALUE thing = RARRAY_PTR(value)[i];
+ add_assoc_zval(php_value, StringValuePtr(key), Phuby_value_to_zval(rt, thing));
+ }
+ VALUE map = rb_iv_get(rt, "@proxy_map");
+ rb_hash_aset(map, INT2NUM((int)php_value), value);
+ }
+ break;
case T_NIL:
ZVAL_NULL(php_value);
break;
View
9 test/test_array.rb
@@ -1,6 +1,15 @@
require 'helper'
class TestArray < Phuby::TestCase
+ def test_move_to_runtime
+ Phuby::Runtime.php do |rt|
+ rt['foo'] = [1,2,3]
+ assert_equal 1, rt['foo'][0]
+ assert_equal 2, rt['foo'][1]
+ assert_equal 3, rt['foo'][2]
+ end
+ end
+
def test_array_length
Phuby::Runtime.php do |rt|
rt.eval('$get_length = count($_GET);')
Please sign in to comment.
Something went wrong with that request. Please try again.