Navigation Menu

Skip to content

Commit

Permalink
Update README.asciidoc
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jul 23, 2015
1 parent 454c01f commit 4a6e63f
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions script/README.asciidoc
Expand Up @@ -42,26 +42,26 @@ JSR-223 (javax.script) compatible::
Invoke script using the javax.script API:
[source,java]
----
// Using ScriptEngineManager
ScriptEngineManager manager = new ScriptEngineManager(getClass().getClassLoader());
ScriptEngine engine = manager.getEngineByExtension("fsh");
// or fetching from the AddonRegistry
@Inject
ForgeScriptEngineFactory factory;
//and
ScriptEngine engine = factory.getScriptEngine();
// Using ScriptEngineManager
ScriptEngineManager manager = new ScriptEngineManager(getClass().getClassLoader());
ScriptEngine engine = manager.getEngineByExtension("fsh");
// or fetching from the AddonRegistry
@Inject
ForgeScriptEngineFactory factory;
//and
ScriptEngine engine = factory.getScriptEngine();
// Ready to execute
ScriptContext scriptContext = ScriptContextBuilder.create().currentResource(currentResource).stdout(output.out()).stderr(output.err()).build();
Result result = (Result) engine.eval("touch foo.txt", scriptContext);
// Ready to execute
ScriptContext scriptContext = ScriptContextBuilder.create().currentResource(currentResource).stdout(output.out()).stderr(output.err()).build();
Result result = (Result) engine.eval("touch foo.txt", scriptContext);
----
Support ScriptFileResource::
You can use `ResourceFactory` to get a handle on a `ScriptFileResource` and evaluate it, be it a Forge script or any JSR-223 compatible implementation.
You can use `ResourceFactory` to get a handle to a `ScriptFileResource` and evaluate it, be it a Forge script or any JSR-223 compatible implementation.
[source,java]
----
// it could be a JavaScript file or any other JSR-223 compatible engine.
ScriptFileResource scriptResource = resourceFactory.create(ScriptFileResource.class, new File("forge.fsh"));
ScriptContext context = ScriptContextBuilder.create().currentResource(tmpDir).build();
scriptResource.eval(context);
// it could be a JavaScript file or any other JSR-223 compatible engine.
ScriptFileResource scriptResource = resourceFactory.create(ScriptFileResource.class, new File("forge.fsh"));
ScriptContext context = ScriptContextBuilder.create().currentResource(tmpDir).build();
scriptResource.eval(context);
----

0 comments on commit 4a6e63f

Please sign in to comment.