On 14 feb, 17:07, Christophe Grand <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] a écrit :
>
> > My idea was to change Rhino so to change the eval function and add a
> > printing statement.
>
> > Is it feasable?
>
> Yes but not from within the shell. You have to modifiy the sheel or
> build your own environment.
>
> For the "printing eval" part: create a java class implementing
> org.mozilla.javascript.Callable with the method below:
>
> Object call(Context cx, Scriptable scope, Scriptable thisObj,
> java.lang.Object[] args) {
> System.out.println(args[0]);
> return cx.evaluateString(scope, args[0], "-", 1);
>
> }
>
> And put an instance of it in the global scope under the name "eval".
Thanks! However, a faculty mate already worked with Rhino and proposed
me to add the following method in the Global.java file of the shell:
public static Object eval(Context cx, Scriptable thisObj,Object[]
args, Function funObj)
{
PrintStream out = getInstance(funObj).getOut();
for (int i=0; i < args.length; i++) {
if (i > 0)
out.print(" ");
// Convert the arbitrary JavaScript value into a string form.
String s = Context.toString(args[i]);
out.print(s);
}
out.println();
cx.evaluateString(ScriptableObject.getTopLevelScope(thisObj),
args[0].toString(), "-", 1, null);
return Context.getUndefinedValue();
}
It is a combination of eval function and the print function defined in
the Shell. Besides, I have to add the string "eval" to the array
defined in the public void init(Context cx) method. The array is
called: String[] names
Now when I invoke the Shell this function is executed instead of the
standard one.
Besides, I would like also to change the unescape function, so to add
the same print functionality. Your first suggestion for eval function
seems to be enough for me. In case I need to change it as eval, that
is, modifying the source code, then I will ask you where to find it.
Thank you very much!
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino