← Typed assets

Assets.image

luastra/assets
Assets.image(id: string): Image

Creates a typed reference to an image declared in luastra.json. Construction validates the asset identifier and preserves its media kind so an image cannot be passed accidentally where audio or a font is required.

Before you use it

Add luastra/assets to this module's dependencies in luastra.json, then import it with require("luastra/assets"). Declare the referenced file in luastra.json with its stable asset id and admitted media type. Image assets are PNG, JPEG, WebP, or AVIF; audio assets and WOFF2 fonts use their own declared types.

How it fits

The constructor validates an asset id and returns a typed reference synchronously. It does not read a file. Assets.uri exposes the packaged asset URI for a consuming UI or Media API.

When to use it

Use Assets.image at module initialization or in a small asset helper when UI.Image needs packaged artwork. The identifier must match an admitted image asset; this function does not load arbitrary files or remote URLs.

Parameters

ParameterType / valuesDescription
idstringManifest asset ID whose declared media type is an admitted image.

Returns

Image — a typed image reference admitted from the project manifest.

What happens next

A checked reference or canonical asset URI that a compatible API can consume.

Failures and fixes

A malformed id, missing manifest entry, wrong media kind, unsupported media type, or missing source file fails during project checking or packaging. Assets.font can be applied through UI.TextStyle in the 0.3 source SDK. A missing or wrong-kind font fails when the rendered tree resolves its asset; a failed browser font decode/load retains the selected fallback.

Availability

Public-source alpha API in 0.5.0-alpha; supported consumers vary by asset kind.

Focused example

local Assets = require("luastra/assets")
local cardBack = Assets.image("image/card-back")

Complete inventory

View all pages in Typed assets
← Previous: Assets.ReferenceNext: Assets.audio →