import reports imports
This commit is contained in:
1 parent
a841755d61
commit
953dd1c2a5
2 files changed
+23
-5
No files matched your search
@@ -14,7 +14,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public abstract class ScriptHost
|
||||
{
|
||||
public class ModuleData
|
||||
public static class ModuleData
|
||||
{
|
||||
Module parent;
|
||||
public Map<String, FunctionValue> globalFunctions = new Object2ObjectOpenHashMap<>();
|
||||
@@ -96,7 +96,7 @@ public abstract class ScriptHost
|
||||
Module module = getModuleOrLibraryByName(moduleName);
|
||||
if (modules.containsKey(module.getName())) return; // aready imported, once again, in case some discrepancies in names?
|
||||
modules.put(module.getName(), module);
|
||||
ModuleData data = new ModuleData(module);
|
||||
ModuleData data = new ModuleData(module);
|
||||
initializeModuleGlobals(data);
|
||||
moduleData.put(module, data);
|
||||
runModuleCode(c, module);
|
||||
@@ -134,6 +134,20 @@ public abstract class ScriptHost
|
||||
}
|
||||
}
|
||||
|
||||
public Stream<String> availableImports(String moduleName)
|
||||
{
|
||||
Module source = modules.get(moduleName);
|
||||
ModuleData sourceData = moduleData.get(source);
|
||||
if (sourceData == null)
|
||||
{
|
||||
throw new InternalExpressionException("Cannot import from module that is not imported");
|
||||
}
|
||||
return Stream.concat(
|
||||
globaVariableNames(source, s -> s.startsWith("global_")),
|
||||
globaFunctionNames(source, s -> true)
|
||||
).distinct().sorted();
|
||||
}
|
||||
|
||||
protected abstract Module getModuleOrLibraryByName(String name); // this should be shell out in the executor
|
||||
|
||||
protected abstract void runModuleCode(Context c, Module module); // this should be shell out in the executor
|
||||
|
||||
Reference in new issue
Block a user