تضمين
Translation status: العربية reader-locale proof. Term names and code fences follow the ar pack; supporting prose may still be English.
Embeds a package file into a module constant at build time.
Syntax: const <type> <name> = embed \"<path>\"
Category#
comptime
Related#
Examples#
radix/corpus/insere/insere.fab (canonical · keyword)#
Embeds a package file into a module constant at build time.
# =============================================================================
# تضمين — Embeds a package file into a module constant at build time.
# =============================================================================
#
# What this teaches:
# • Build-time embed — `const T X = embed "path"` reads a file while compiling; the program carries its contents as a literal.
# • One keyword, two results — the declared type decides: `string` requires valid UTF-8, `bytes` takes the raw bytes.
# • Package-relative paths — resolved against the package root (the nearest `faber.toml`), or this file's directory when there is none.
#
# Common mistakes:
# • Using an absolute path or `..` to reach outside the package — both are compile errors (SEM061).
# • Declaring `string` for a binary file — invalid UTF-8 is a compile error; declare `bytes`.
# • Expecting a runtime read — changing the file needs a rebuild; for run-time I/O use a `call` route.
#
# See also: سكوني, نص, بايتات, بادئة
# =============================================================================
# تضمين — build-time file embed (en `embed`)
#
# const <type> <name> = embed "<path>"
#
# GRAMMAR:
# fixum_decl :← 'ثابت' type_annotation IDENTIFIER '=' const_init
# const_init :← insere_expr | expression
# insere_expr :← 'تضمين' STRING
#
# EXPECTED OUTPUT:
# insere.expected — the embedded text, its length, and the byte count.
const string NUNTIUS = embed "nuntius.txt"
const bytes SIGNUM = embed "signum.bin"
class Tabula {
static string TITULUS = embed "nuntius.txt"
}
# `embed` is contextual: directly before a string literal it is the embed; any
# other use of the name, like this call, is an ordinary identifier.
fn embed(int n) → int {
return n * 2
}
main {
print NUNTIUS
print NUNTIUS.length()
print SIGNUM.length()
print embed(21)
}Expected output:
salve ex tabula
15
6
42