GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - lucko/ScriptController: Extended API for Java's Scripting Engine framework

BranchesTags
Open more actions menu

Latest commit

 

History

12 Commits
12 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

Repository files navigation

ScriptController

Extended API for Java's Scripting Engine framework (javax.script) with the Nashorn JavaScript engine.

ScriptController provides:

  • Automatic detection & reloading of script files
  • Global export registry system
  • Builder-style API for constructing new controllers and environments

Usage

The main entry point into the API is via ScriptController.

The following is a valid way to obtain an instance.

ScriptController controller = ScriptController.builder().build();

However, it's likely that you'll want to customize certain aspects of the controller.

Logger logger = Logger.getLogger("my-logger");
SpecialObject mySpecialObject = new SpecialObject();

EnvironmentSettings environmentSettings = EnvironmentSettings.builder()
        .initScript("init.js")
        .withDefaultPackageImport("java.util")
        .withDefaultTypeImport("me.lucko.test.MyTestClass")
        .withDefaultTypeImport("com.example.RuntimeManager")
        .withBindings((script, accumulator) -> {
            accumulator.put("specialObject", mySpecialObject);
            accumulator.put("bootstrap", this);
        })
        .build();

ScriptController controller = ScriptController.builder()
        .logger(SystemLogger.usingJavaLogger(logger))
        .withDirectory(Paths.get("scripts/"))
        .defaultEnvironmentSettings(environmentSettings)
        .build();

These are just a few examples of the available settings. ScriptController is designed with flexibility in mind.

ScriptControllers "manage" a number of ScriptEnvironments, which center around a root scripts directory.

You can define these environments when building the controller, using .withDirectory(...), or after the controller has been constructed.

ScriptController controller = ScriptController.builder().build();
ScriptEnvironment env = controller.setupNewEnvironment(Paths.get("src"), EnvironmentSettings.defaults());

ScriptEnvironment exposes further instances which make up the overall system.

ExportRegistry exports = env.getExportRegistry();
EnvironmentScriptLoader loader = env.getLoader();
ScriptRegistry scriptRegistry = env.getScriptRegistry();
  • ExportRegistry holds a shared set of "exports". This is effectively a namespace which is shared between scripts.
  • EnvironmentScriptLoader is responsible for loading/reloading/unloading scripts, and monitoring the source directory for changes.
  • ScriptRegistry holds all currently loaded scripts.

The library has extensive JavaDocs - all public classes, methods and fields have documentation. More detailed commentary and explanation on the purpose, behaviour and usage of methods and classes can be found there.

About

Extended API for Java's Scripting Engine framework

Topics

javax-scriptnashornscript-loader

Resources

Readme
MIT license
Activity

Stars

13 stars

Watchers

2 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.