ELoader
From Erights
(Difference between revisions)
m |
|||
Line 13: | Line 13: | ||
} | } | ||
- | + | = Using multiple modules = | |
- | This avoids the need to set classpath and avoids conflicts between different packages. See [http://www.eros-os.org/pipermail/e-lang/2010-February/013416.html] for details. | + | If a program is made up of multiple modules, a separate loader can be created for each one. Each module is given its own loader as '''<this>''', as well as loaders for its dependencies. For example, here we have two modules. "prog" is a program that depends on a library called "libfoo". |
+ | |||
+ | def <libfoo> := makeELoader(<file:.../libfoo>, ["this__uriGetter" => <libfoo>], "libfoo$") | ||
+ | def <prog> := makeELoader(<file:.../prog>, ["this__uriGetter" => <prog>, => <libfoo>], "prog$") | ||
+ | |||
+ | def app := <prog:makeApplication>(...) | ||
+ | |||
+ | * Within libfoo, the library can load other emakers from itself using e.g. '''<this:somefile>'''. | ||
+ | * Within prog, a file can load other emakers from prog using e.g. '''<this:somefile>''', or from libfoo using '''<libfoo:somefile>'''. | ||
+ | |||
+ | You could also wrap the '''<libfoo>''' given to prog to only expose its public API. | ||
+ | |||
+ | This avoids the need to set classpath and avoids conflicts between different packages. | ||
+ | |||
+ | = See also = | ||
+ | |||
+ | See [http://www.eros-os.org/pipermail/e-lang/2010-February/013416.html] for details. |
Revision as of 13:20, 9 June 2010
When you run a .e or (.updoc) file, it is given a loader called <this> which can be used to import .emaker files from the same directory (or from a sub-directory).
For example:
# main.e def makeMyObject := <this:makeMyObject> def obj := makeMyObject() ...
# makeMyObject.emaker def makeMyObject() { ... }
Using multiple modules
If a program is made up of multiple modules, a separate loader can be created for each one. Each module is given its own loader as <this>, as well as loaders for its dependencies. For example, here we have two modules. "prog" is a program that depends on a library called "libfoo".
def <libfoo> := makeELoader(<file:.../libfoo>, ["this__uriGetter" => <libfoo>], "libfoo$") def <prog> := makeELoader(<file:.../prog>, ["this__uriGetter" => <prog>, => <libfoo>], "prog$") def app := <prog:makeApplication>(...)
- Within libfoo, the library can load other emakers from itself using e.g. <this:somefile>.
- Within prog, a file can load other emakers from prog using e.g. <this:somefile>, or from libfoo using <libfoo:somefile>.
You could also wrap the <libfoo> given to prog to only expose its public API.
This avoids the need to set classpath and avoids conflicts between different packages.
See also
See [1] for details.