|
From: <php...@li...> - 2009-01-05 16:44:52
|
Hi,
> I want to wrap two PHP objects as closures, pass them to Java, and in
> Java call a method on the first closure with the second closure as
> parameter [argument]
In pseudo code (please see the JSR 223 API for details):
String pA = "class A{function testA($b){echo $b->testB();}}\n"
String pB = "class B{function testB(){echo 'hello world';}}\n"
String test = "<?php "+pA+Pb+" $thiz=java_context()->getAttribute("thiz"); $thiz->call(java_closure(new A()), java_closure(new B()); ?>
public void doWork (){
scriptEngine = new ScriptEngineManager().getEngineByName("php-invocable");
scriptEngine.put("thiz", this);
scriptEngine.eval(test);
((Closeable)scriptEngine).close();
}
static interface IA { public void testA(IB cc1); }
static interface IB { public void testB(); }
public void call(Object $ccA, Object $ccB) {
IA ccA = scriptEngine.getInterface($ccA, IA);
IB ccB = scriptEngine.getInterface($ccB, IB);
ccA.testA(ccB);
}
> The problem is that on the php side I get a new object of
> type PhpProcedure instead of the closure/proxy I created before.
Yes, the type is determined lazily. Why is that a problem?
> Therefore within the method I always get the wrong
> parameter passed in.
I think this is a misunderstanding. If you don't specify the type, either via getInterface() (see above) or by calling java_closure() with three arguments, the generated procedure is generic, i.e. you cannot call the procedure "testA" on it.
Regards,
Jost Boekemeier
|