Skip to content

BaseLanguage ​

com.jsmacrosce.jsmacros.core.language.BaseLanguage

Since1.1.3

Base implementation for script-language integrations. Triggered scripts run on the runner's thread pool and their contexts are closed after execution unless kept alive.

Type Parameters ​

  • U: language-specific runtime context type parameter
  • T: script context type used by this language implementation

Constructors ​

new BaseLanguage ​

new BaseLanguage(Extension extension, Core<?, ?> runner)#
Stores the extension and runner references used by this language implementation.

Parameters:

  • extension: extension associated with this language
  • runner: core used for execution and library lookup

Fields ​

extension ​

extension: Extensionread-only#
The extension associated with this language implementation.

preThread ​

preThread: Runnable#
Hook run on the worker thread before each trigger's execution handling begins; defaults to an empty action. A null hook or one that throws prevents normal execution, error handling, and cleanup.

Methods ​

createContext ​

createContext(BaseEvent event, File file): T extends BaseScriptContext<U>#
Creates the language-specific script context used by trigger execution. Implementations are expected to return a non-null context.

Parameters:

  • event: triggering event, or null
  • file: origin file, or null for source-string execution
Returns: non-null context for the script run

retrieveLibs ​

retrieveLibs(T extends BaseScriptContext<U> context): Map<String, BaseLibrary>#
Retrieves shared, per-language, and per-execution libraries applicable to this context. Shared and per-language instances are reused; per-execution instances are constructed for this call. A per-execution library constructor failure propagates as a RuntimeException.

Parameters:

  • context: context used to construct and select per-execution libraries
Returns: map of applicable library names to instances

retrieveOnceLibs ​

retrieveOnceLibs(): Map<String, BaseLibrary>#
Retrieves the shared and per-language library instances without constructing per-execution libraries.
Returns: map of library names to shared or per-language instances

retrievePerExecLibs ​

retrievePerExecLibs(T extends BaseScriptContext<U> context): Map<String, BaseLibrary>#
Creates new per-execution library instances for this call. A library constructor failure propagates as a RuntimeException.

Parameters:

  • context: context used to construct and select per-execution libraries
Returns: map of per-execution library names to instances

trigger ​

trigger(ScriptTrigger macro, BaseEvent event, Runnable then, Consumer<Throwable> catcher): EventContainer<T extends BaseScriptContext<U>>#
Schedules execution of a configured script trigger. The script file is resolved against the runner's macro folder when relative and checked for existence and regular-file status on the worker thread. The returned container is created before queuing and does not represent a script result; missing or directory paths disable the original trigger and are reported through catcher when supplied. Failures while copying the trigger or creating its context occur before queuing. The worker's preThread hook runs outside the execution cleanup and error handling, so a null hook or one that throws skips those paths.

Parameters:

  • macro: trigger configuration; its settings are copied for execution, while its enabled flag is disabled if the resolved file is missing or a directory
  • event: triggering event, or null
  • then: optional callback run after normal execution, or null; callback failures are logged directly
  • catcher: optional handler for execution or file-check failures; failures thrown by it are logged
Returns: container holding the created context and its trigger lock
trigger(String lang, String script, File fakeFile, BaseEvent event, Runnable then, Consumer<Throwable> catcher): EventContainer<T extends BaseScriptContext<U>>#
Schedules execution of source text using the supplied language identifier; fakeFile supplies origin metadata, and BaseLanguage itself does not read or check it (the createContext(BaseEvent, File) implementation may). Unlike the file-trigger overload, failures from then are passed to catcher. The worker's preThread hook runs outside execution error handling and cleanup, so a null hook or one that throws skips those paths.

Parameters:

  • lang: language identifier passed to the implementation's execution hook
  • script: source text to execute
  • fakeFile: origin file metadata, or null
  • event: triggering event, or null
  • then: optional callback run after normal execution
  • catcher: optional handler for execution or completion-callback failures
Returns: container holding the created context and its trigger lock