An equivalent of package.searchers for compile time

This is a tracking issue for a more sophisticated method of loading Fennel macros at compile time.

One possible use for this is to expose Fennel macros to end users of an application which embeds Fennel modules, including user-facing macros. As of today, this can only be done by hand via running fennel.eval with compile scope, e.g.

(local fennel (require :fennel))
(local compiler (require :fennel.compiler))

(local str (with-open [file (io.open :path/to/macros.fnl :r)]
             (file:read :a)))
(local opts {:scope compiler.scopes.compiler})

(fennel.eval str opts)
Assigned to
15 days ago
8 days ago

~technomancy 15 days ago

A little more detail about how it currently works:

The entry point is the require-macros special. Any import-macros calls expand to this. In require-macros it calls compiler-env-domodule; this function takes a module name and returns the module itself. But it looks up the module in a way that is not extensible: by searching fennel.path and using io.open to check for existence of each possible filename on the path.

We need to replace this with an extensible model, and one that is based on package.searchers would fit the bill. We can introduce a new fennel.module-searchers function which defaults to containing one function that works the current way but allows people to add their own searcher functions. Just like with normal modules, custom searcher functions would take a module name as an argument and (if it's able to find the module) returns a function which, when called, would return the macro module.


So for instance, a love2d-based searcher would know how to check inside the game archive file for a macro module that is bundled with the rest of the source rather than having to look directly on disk.

This might actually solve #40 now that I think about it.

~technomancy 9 days ago

This is addressed by a patch here: https://lists.sr.ht/~technomancy/fennel/patches/21778

~technomancy REPORTED FIXED 8 days ago

Applied in 761c5c6

Register here or Log in to comment, or comment via email.