Lyricdev
GitHub

LYR-CT0004

an embed that cannot read its file

error · spec 11-metaprogramming

A call to std.core.embed would run in the built program instead of at compile time, or names a file that does not exist or lies outside the package's directory.

Explanation

embed(path) reads a file while the program compiles and makes its content a value of the program. It runs only inside a comptime site, and it reads only files within the package, found relative to the file that calls it.

Write comptime embed("…"), and check that the path names a file inside the package.

Wrong

//- src/main.lyr
import std.core { embed };

fn main(): void {
    let text = embed("greeting.txt");
    assert(text.length() == 4);
}
//- src/greeting.txt
hi!
//- src/main.lyr
import std.core { embed };

fn main(): void {
    let text = comptime embed("greeting.txt");
    assert(text.length() == 4);
}
//- src/greeting.txt
hi!