Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

return values are proxied back, rails adapter cleaned up

  • Loading branch information...
commit b01299cd0fe98c1adadf876e46d42af3d13fc14a 1 parent 612f504
Aaron Patterson authored November 16, 2009
8  ext/phuby/phuby_runtime.c
@@ -15,11 +15,17 @@ PHP_METHOD(RubyProxy, __call)
15 15
 
16 16
   VALUE rt = rb_funcall(cPhubyRuntime, rb_intern("instance"), 0);
17 17
 
18  
-  rb_funcall(rt, rb_intern("call"), 3,
  18
+  VALUE ret = rb_funcall(rt, rb_intern("call"), 3,
19 19
       INT2NUM((int)this_ptr),
20 20
       rb_str_new(function, function_len),
21 21
       ZVAL2VALUE(rt, args)
22 22
   );
  23
+
  24
+  if(ret != Qnil) {
  25
+    zval * rv  = Phuby_value_to_zval(rt, ret);
  26
+    RETURN_ZVAL(rv, 1, 1);
  27
+  }
  28
+  RETURN_NULL();
23 29
 }
24 30
 
25 31
 zend_class_entry *php_ruby_proxy;
16  lib/phuby/rails.rb
@@ -12,12 +12,28 @@ def header value, op
12 12
     end
13 13
   end
14 14
 
  15
+  class ControllerProxy
  16
+    def initialize controller
  17
+      @controller = controller
  18
+    end
  19
+
  20
+    def method_missing name
  21
+      @controller.instance_variable_get :"@#{name}"
  22
+    end
  23
+  end
  24
+
  25
+  def initialize view
  26
+    @controller = view.controller
  27
+    @proxy      = ControllerProxy.new @controller
  28
+  end
  29
+
15 30
   def render template, *args
16 31
     filename = File.join template.load_path, template.template_path
17 32
     events   = Events.new(200, {}, '')
18 33
     Dir.chdir(File.dirname(filename)) do
19 34
       Phuby::Runtime.php do |rt|
20 35
         rt.eval "date_default_timezone_set('America/Los_Angeles');"
  36
+        rt['at'] = @proxy
21 37
         rt.with_events(events) do
22 38
           open(filename) { |f| rt.eval f }
23 39
         end
13  test/test_object.rb
@@ -15,6 +15,10 @@ def hello
15 15
     def value x
16 16
       @values << x
17 17
     end
  18
+
  19
+    def saying
  20
+      "hello"
  21
+    end
18 22
   end
19 23
 
20 24
   def test_stringio
@@ -41,4 +45,13 @@ def test_method_call_with_args
41 45
     end
42 46
     assert_equal %w{ foo bar }, x.values
43 47
   end
  48
+
  49
+  def test_return_value
  50
+    x = FunObject.new
  51
+    Phuby::Runtime.php do |rt|
  52
+      rt['x'] = x
  53
+      rt.eval('$y = $x->saying();')
  54
+      assert_equal 'hello', rt['y']
  55
+    end
  56
+  end
44 57
 end

0 notes on commit b01299c

Please sign in to comment.
Something went wrong with that request. Please try again.