| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
import org.mozilla.javascript.*; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public class RunScript4 { |
| 16 |
public static void main(String args[]) |
| 17 |
throws Exception |
| 18 |
{ |
| 19 |
Context cx = Context.enter(); |
| 20 |
try { |
| 21 |
Scriptable scope = cx.initStandardObjects(); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
ScriptableObject.defineClass(scope, Counter.class); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
Object[] arg = { new Integer(7) }; |
| 32 |
Scriptable myCounter = cx.newObject(scope, "Counter", arg); |
| 33 |
scope.put("myCounter", scope, myCounter); |
| 34 |
|
| 35 |
String s = ""; |
| 36 |
for (int i=0; i < args.length; i++) { |
| 37 |
s += args[i]; |
| 38 |
} |
| 39 |
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null); |
| 40 |
System.err.println(Context.toString(result)); |
| 41 |
} finally { |
| 42 |
Context.exit(); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
} |
| 47 |
|