Skip to content

Implement #@import directive #295

Open
@imagejan

Description

@imagejan

As discussed with @ctrueden, this should allow scripts to import the output objects of other scripts.

Given a script:

#@script(name="coolutils")
#@output imagefunctions
imagefunctions = {
  tile(a) {
  }
}

This should be importable like this:

#@import("coolutils")
imagefunctions.tile(a)

or with a local scope:

#@import("coolutils", scope="cool")
cool.imagefunctions.tile(a)

Subtasks:

  • ImportProcessor implements ScriptProcessor
    • Harvest the import statements and stash them in the ScriptInfo as a property via info.set(String, String)
    • Probably stash them in the ScriptService in a map
  • ScriptImportPreprocessor implements PreprocessorPlugin
    • If the module being preprocessed is not a ScriptModule, stop.
    • Otherwise:
      • for importName in ((ScriptInfo) module.getInfo()).getProperty("imports"):
        • moduleService.run(moduleService.getModuleByName(importName)
        • ((ScriptModule) module).getEngine() .getBindings(ScriptContext.ENGINE_SCOPE).putAll(outputs)
  • Needed sub tasks:
    • ModuleService#getModuleByName: getModules().stream().filter(m -> name.equals(m.getName()).limit(1)...
    • ScriptInfo.getProperty(String) / ScriptInfo.setProperty(String, Object)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions