Import: Simplify the interpreter's import hook.
The interpreter's import hook is currently written as this:
typedef void (*lily_import_func)(lily_state *s, const char *root_dir,
const char *package_base, const char *name);
Here are some reasons one might want to implement custom importing behavior:
-
Sandboxing. A sandbox might forbid loading relative paths and/or forbid loading libraries.
-
Embedders: Embedders may want to load Lily code from a non-traditional source (ex: from a single compressed source).
-
Testing: The testing system can simulate less-common import setups without needing to actually create them through redirection.
The problem with the import hook as it's currently defined is that all of the above need to implement the interpreter's import path creation. None of the above are interested in how the interpreter's paths are created, and the path creation may even change.
I'm planning on changing the import hook to be as follows:
typedef void (*lily_import_func)(lily_state *s, const char *path);
The interpreter's api would be extended with 'lily_path_is_native', a function for checking if the last path sent to the import hook is native.
I think that the interpreter should record the paths that the import hook ends up trying, instead of the paths that it originally sent.
I'm planning on taking this issue before the other import-related ones, since it will be a more fundamental change in how import works. The other changes can be layered on top since they won't break existing embedders.