Hi all,
Am Dienstag, den 11.03.2008, 11:06 +0100 schrieb Carsten Ziegeler:
> Rethinking, I think we should make these two changes:
> a) Add the return value to the eval() method
+1
> b) Make SlingScript adaptable and allow to adapt it to
> javax.script.Invocable [1].
>
> The only (minor) drawback is that the adaption is only allowed *after*
> eval is called.
Invocable is an interface, which is generally implemented by a
ScriptEngine, so adapting a Script to Invocable is comparable to adapt
it to a ScriptEngine and I would not do that.
How about this: we create a new SlingScript.call(String method,
Object... args) method which will be implemented such, that a new
(virtual) script is created from the original script appended with the
method call.
Example: Let the script source be
function sampleFunction() {
...
}
function anotherFunction(arg1, arg2) {
...
}
Now, we call script.call("sampleFunction", null).
This would result in the virtual (combined) script:
function sampleFunction() {
...
}
function anotherFunction(arg1, arg2) {
...
}
sampleFunction();
Likewise, calling script.call("anotherFunction", 5, "astring") would get
the virtual script:
function sampleFunction() {
...
}
function anotherFunction(arg1, arg2) {
...
}
anotherFunction(5, "astring");
To build the method call, we may use the
ScriptEngineFactory.getMethodCallSyntax().
Finally the virtual script is actually evaluated.
This would also allow this for any scripting language ...
WDYT ?
Regards
Felix