Skip to content

Commit f4c47e0

Browse files
committed
ScriptREPL: only include the interpreted languages
Compiled languages (e.g., the JavaScriptLanguage) will not work as desired within the intepreter.
1 parent b9ad594 commit f4c47e0

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/main/java/org/scijava/script/ScriptREPL.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public class ScriptREPL {
7575

7676
private final PrintStream out;
7777

78+
/** List of interpreter-friendly script languages. */
79+
private List<ScriptLanguage> languages;
80+
7881
/** The currently active interpreter. */
7982
private ScriptInterpreter interpreter;
8083

@@ -88,6 +91,19 @@ public ScriptREPL(final Context context, final OutputStream out) {
8891
(PrintStream) out : new PrintStream(out);
8992
}
9093

94+
/**
95+
* Gets the list of languages compatible with the REPL.
96+
* <p>
97+
* This list will match those given by {@link ScriptService#getLanguages()},
98+
* but filtered to exclude any who report {@code true} for
99+
* {@link ScriptLanguage#isCompiledLanguage()}.
100+
* </p>
101+
*/
102+
public List<ScriptLanguage> getInterpretedLanguages() {
103+
if (languages == null) initLanguages();
104+
return languages;
105+
}
106+
91107
/** Gets the script interpreter for the currently active language. */
92108
public ScriptInterpreter getInterpreter() {
93109
return interpreter;
@@ -123,7 +139,7 @@ public void initialize() {
123139
out.println("Welcome to the SciJava REPL!");
124140
out.println();
125141
help();
126-
final List<ScriptLanguage> langs = scriptService.getLanguages();
142+
final List<ScriptLanguage> langs = getInterpretedLanguages();
127143
if (langs.isEmpty()) {
128144
out.println("--------------------------------------------------------------");
129145
out.println("Uh oh! There are no SciJava script languages available!");
@@ -245,7 +261,7 @@ public void langs() {
245261
final List<String> names = new ArrayList<>();
246262
final List<String> versions = new ArrayList<>();
247263
final List<Object> aliases = new ArrayList<>();
248-
for (final ScriptLanguage lang : scriptService.getLanguages()) {
264+
for (final ScriptLanguage lang : getInterpretedLanguages()) {
249265
names.add(lang.getLanguageName());
250266
versions.add(lang.getLanguageVersion());
251267
aliases.add(lang.getNames());
@@ -272,6 +288,16 @@ public static void main(final String... args) throws Exception {
272288

273289
// -- Helper methods --
274290

291+
/** Initializes {@link #languages}. */
292+
private synchronized void initLanguages() {
293+
if (languages != null) return;
294+
final List<ScriptLanguage> langs = new ArrayList<>();
295+
for (final ScriptLanguage lang : scriptService.getLanguages()) {
296+
if (!lang.isCompiledLanguage()) langs.add(lang);
297+
}
298+
languages = langs;
299+
}
300+
275301
/** Populates the bindings with the context + services + gateways. */
276302
private void populateBindings(final Bindings bindings) {
277303
bindings.put("ctx", context);

0 commit comments

Comments
 (0)