# BaseLanguage

`com.jsmacrosce.jsmacros.core.language.BaseLanguage`

**Since:** 1.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 {#com.jsmacrosce.jsmacros.core.language.BaseLanguage_constructor-Extension-Core-}

```js
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 {#com.jsmacrosce.jsmacros.core.language.BaseLanguage_extension}

```js
extension: Extension
```

The extension associated with this language implementation.

### preThread {#com.jsmacrosce.jsmacros.core.language.BaseLanguage_preThread}

```js
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 {#com.jsmacrosce.jsmacros.core.language.BaseLanguage_createContext-BaseEvent-File-}

```js
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 {#com.jsmacrosce.jsmacros.core.language.BaseLanguage_retrieveLibs-T-}

```js
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](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/RuntimeException.html).

**Parameters:**
- `context`: context used to construct and select per-execution libraries

**Returns:** map of applicable library names to instances

### retrieveOnceLibs {#com.jsmacrosce.jsmacros.core.language.BaseLanguage_retrieveOnceLibs-}

```js
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 {#com.jsmacrosce.jsmacros.core.language.BaseLanguage_retrievePerExecLibs-T-}

```js
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](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/RuntimeException.html).

**Parameters:**
- `context`: context used to construct and select per-execution libraries

**Returns:** map of per-execution library names to instances

### trigger {#com.jsmacrosce.jsmacros.core.language.BaseLanguage_trigger-ScriptTrigger-BaseEvent-Runnable-Consumer-}

```js
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 {#com.jsmacrosce.jsmacros.core.language.BaseLanguage_trigger-String-String-File-BaseEvent-Runnable-Consumer-}

```js
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)](#com.jsmacrosce.jsmacros.core.language.BaseLanguage_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
