diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-05-29 15:45:57 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-05-31 22:33:40 +0200 |
| commit | e023bf2ac9f5796355d9485afc16781196bf212b (patch) | |
| tree | 26d4487de0c4e2d0f69182483301de867cb5fa34 /src/library/image.rs | |
| parent | 9f77f09aacd1fb0fd6138a6d16ed2755f6bfae3f (diff) | |
Module loading system
Detects cyclic imports and loads each module only once per compilation.
Diffstat (limited to 'src/library/image.rs')
| -rw-r--r-- | src/library/image.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/library/image.rs b/src/library/image.rs index cd6a97d1..7fabfe35 100644 --- a/src/library/image.rs +++ b/src/library/image.rs @@ -20,12 +20,14 @@ pub fn image(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { let mut node = None; if let Some(path) = &path { - if let Some(id) = ctx.cache.image.load(ctx.loader, &path.v) { - let img = ctx.cache.image.get(id); - let dimensions = img.buf.dimensions(); - node = Some(ImageNode { id, dimensions, width, height }); - } else { - ctx.diag(error!(path.span, "failed to load image")); + if let Some((resolved, _)) = ctx.resolve(&path.v, path.span) { + if let Some(id) = ctx.cache.image.load(ctx.loader, &resolved) { + let img = ctx.cache.image.get(id); + let dimensions = img.buf.dimensions(); + node = Some(ImageNode { id, dimensions, width, height }); + } else { + ctx.diag(error!(path.span, "failed to load image")); + } } } |
