Permalink
Browse files

return values are proxied back, rails adapter cleaned up

  • Loading branch information...
tenderlove committed Nov 17, 2009
1 parent 612f504 commit b01299cd0fe98c1adadf876e46d42af3d13fc14a
Showing with 36 additions and 1 deletion.
  1. +7 −1 ext/phuby/phuby_runtime.c
  2. +16 −0 lib/phuby/rails.rb
  3. +13 −0 test/test_object.rb
@@ -15,11 +15,17 @@ PHP_METHOD(RubyProxy, __call)
VALUE rt = rb_funcall(cPhubyRuntime, rb_intern("instance"), 0);
- rb_funcall(rt, rb_intern("call"), 3,
+ VALUE ret = rb_funcall(rt, rb_intern("call"), 3,
INT2NUM((int)this_ptr),
rb_str_new(function, function_len),
ZVAL2VALUE(rt, args)
);
+
+ if(ret != Qnil) {
+ zval * rv = Phuby_value_to_zval(rt, ret);
+ RETURN_ZVAL(rv, 1, 1);
+ }
+ RETURN_NULL();
}
zend_class_entry *php_ruby_proxy;
View
@@ -12,12 +12,28 @@ def header value, op
end
end
+ class ControllerProxy
+ def initialize controller
+ @controller = controller
+ end
+
+ def method_missing name
+ @controller.instance_variable_get :"@#{name}"
+ end
+ end
+
+ def initialize view
+ @controller = view.controller
+ @proxy = ControllerProxy.new @controller
+ end
+
def render template, *args
filename = File.join template.load_path, template.template_path
events = Events.new(200, {}, '')
Dir.chdir(File.dirname(filename)) do
Phuby::Runtime.php do |rt|
rt.eval "date_default_timezone_set('America/Los_Angeles');"
+ rt['at'] = @proxy
rt.with_events(events) do
open(filename) { |f| rt.eval f }
end
View
@@ -15,6 +15,10 @@ def hello
def value x
@values << x
end
+
+ def saying
+ "hello"
+ end
end
def test_stringio
@@ -41,4 +45,13 @@ def test_method_call_with_args
end
assert_equal %w{ foo bar }, x.values
end
+
+ def test_return_value
+ x = FunObject.new
+ Phuby::Runtime.php do |rt|
+ rt['x'] = x
+ rt.eval('$y = $x->saying();')
+ assert_equal 'hello', rt['y']
+ end
+ end
end

0 comments on commit b01299c

Please sign in to comment.