FastLED 3.10.8
Loading...
Searching...
No Matches
asset.h File Reference

Detailed Description

First-class asset handles for sketches that live under <sketch>/data/.

This header is part of the v1 asset pipeline (FastLED issue #2284).

Usage from a sketch:

fl::UIAudio audio("Audio", FL_ASSET("data/track.mp3"));
fl::UIAudio audio("Audio Input")
#define FL_ASSET(LITERAL_PATH)
Preferred entry point: rejects .. at compile time via FL_STATIC_ASSERT.
Definition asset.h:139

At build time, ci/compiler/asset_scanner.py scans <sketch>/data/ for *.lnk files and emits fastled_js/asset_manifest.json (see ci/wasm_build.py). It accepts both .lnk spellings: the text form this runtime parses, and the JSON form fbuild lnk add writes. At runtime:

  • On WASM, the manifest is consulted to turn the relative path into the URL the browser should fetch.
  • On host/stub, the asset resolves to the file on disk — or, if the raw file is missing but a *.lnk exists alongside, to the URL from the .lnk (same fallback as WASM).

v1 scope: WASM and host/stub only. ESP32 LittleFS / SD-card resolution is future work and intentionally omitted.

Compile-time validation: FL_ASSET("data/../foo.mp3") and any path containing .. segments is rejected via FL_STATIC_ASSERT. The normalized path is stored verbatim; runtime resolution never walks parent directories.

Definition in file asset.h.

#include "fl/stl/int.h"
#include "fl/stl/noexcept.h"
#include "fl/stl/static_assert.h"
#include "fl/stl/string.h"
#include "fl/stl/string_view.h"
#include "fl/stl/url.h"
+ Include dependency graph for asset.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  fl::asset_ref
 Opaque handle to a sketch-local asset. More...
 

Namespaces

namespace  fl
 Base definition for an LED controller.
 
namespace  fl::asset_detail
 

Macros

#define FL_ASSET(LITERAL_PATH)
 Preferred entry point: rejects .. at compile time via FL_STATIC_ASSERT.
 

Functions

constexpr asset_ref fl::asset (const char *path) FL_NO_EXCEPT
 Construct an asset handle from a relative sketch path at runtime.
 
constexpr fl::size fl::asset_detail::clen (const char *s, fl::size n=0) FL_NO_EXCEPT
 Compile-time length of a null-terminated C string.
 
constexpr bool fl::asset_detail::is_parent_at (const char *p, fl::size i) FL_NO_EXCEPT
 Compile-time check: does position i in p start a ".." segment?
 
constexpr bool fl::asset_detail::path_has_parent_segment (const char *p) FL_NO_EXCEPT
 Compile-time check: returns true if the string contains a ".." segment.
 
constexpr bool fl::asset_detail::path_has_parent_segment_at (const char *p, fl::size i) FL_NO_EXCEPT
 Recursive constexpr walk looking for any ".." segment.
 
void fl::register_asset (fl::string_view path, const fl::url &u) FL_NO_EXCEPT
 Public helper: plug an asset mapping at runtime.
 
fl::url fl::resolve_asset (const asset_ref &a) FL_NO_EXCEPT
 Resolve an asset handle to a URL (or local file path) at runtime.