String modulePath = name.replace('.', '/');
// $CWD/foo/bar.mag
File file = new File(modulePath + ".mag");
if (file.exists()) {
return new SourceFile(file.getPath(), readFile(file.getPath()));
}
// $CWD/foo/bar/_init.mag
file = new File(modulePath + "/_init.mag");
if (file.exists()) {
return new SourceFile(file.getPath(), readFile(file.getPath()));
}
// $APPDIR/lib/foo/bar.mag
File appDir = new File(getAppDirectory(), "lib");
file = new File(appDir, modulePath + ".mag");
if (file.exists()) {
return new SourceFile(file.getPath(), readFile(file.getPath()));
}
// $APPDIR/lib/foo/bar/_init.mag
file = new File(appDir, modulePath + "/_init.mag");
if (file.exists()) {
return new SourceFile(file.getPath(), readFile(file.getPath()));
}
throw new IOException("Couldn't find module " + name);
} catch (IOException e) {
e.printStackTrace();