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 945bfd4 commit a853926
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions script/README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ To use this addon, you must add it as a dependency in the *pom.xml* of your `for
----

== Features
javax.script compatible::
Invoke script using the javax.script API:

[source,java]
----
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");
Expand All @@ -56,5 +55,13 @@ javax.script compatible::
// 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.
[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);
----

0 comments on commit a853926

Please sign in to comment.