Embed octet-stream or text

Is there an equivalent of the Embed meta-data from ActionScript, or include_str! and include_bytes! from Rust, in Haxe? I mean, a static, synchronous and relative-path way of embedding file within a library or program. I wish Haxe had the following syntax:

var ba = embed './data.bin' as 'application/octet-stream';

(Note the ./ part; it means relative to the actual Haxe script.)

At least for embedding either text or binary content. If this does not exist, can it be considered as feature?

This would be the closest thing in straight Haxe: Embedding resources (Compiler Features - Resources) - Haxe - The Cross-platform Toolkit

If you move to OpenFL there is a more extensive Assets Library system.

Unfortunately this would not work with libraries. That works for the entry point only (which runs the Haxe compiler command).

Perhaps you could look into using macros for that: Include a file next to a Haxe module file - Macros - Haxe programming language cookbook

1 Like