DefinesMacro
Utilities to access compile-time defines from code. This class provides macro functions to retrieve and parse compiler flags (defines) at compile time, making them available as constants in the generated code.
Ceramic uses defines extensively for configuration values that need to be embedded at compile time, such as asset paths, target-specific settings, and feature flags.
Original source: https://code.haxe.org/category/macros/get-compiler-define-value.html
Static Members
Retrieves a compiler flag value as a string. The value is embedded as a constant in the generated code.
Example:
var version = DefinesMacro.getDefine("app_version"); // "1.0.0"
Name | Type | Description |
---|---|---|
key |
Dynamic | The name of the compiler flag |
Returns | Description |
---|---|
Dynamic | Expression containing the flag value as a string |
Retrieves a compiler flag value that has been double-encoded as JSON. Some Ceramic build tools encode values twice to ensure proper escaping through multiple processing stages.
Example:
var paths = DefinesMacro.getJsonJsonDefine("ceramic_extra_assets_paths"); // ["path1", "path2"]
Name | Type | Description |
---|---|---|
key |
Dynamic | The name of the compiler flag |
Returns | Description |
---|---|
Dynamic | Expression containing the decoded value |
Retrieves a compiler flag value that has been encoded as JSON. Used for complex data structures passed through compiler flags.
Example:
var config = DefinesMacro.getJsonDefine("app_config"); // {debug: true, ...}
Name | Type | Description |
---|---|---|
key |
Dynamic | The name of the compiler flag |
Returns | Description |
---|---|
Dynamic | Expression containing the decoded value |
Retrieves a compiler flag value and parses it as a Float.
Example:
var scale = DefinesMacro.getFloatDefine("ui_scale"); // 1.5
Name | Type | Description |
---|---|---|
key |
Dynamic | The name of the compiler flag |
Returns | Description |
---|---|
Dynamic | Expression containing the parsed float value |
Retrieves a compiler flag value and parses it as an Int.
Example:
var maxPlayers = DefinesMacro.getIntDefine("max_players"); // 4
Name | Type | Description |
---|---|---|
key |
Dynamic | The name of the compiler flag |
Returns | Description |
---|---|
Dynamic | Expression containing the parsed integer value |
Retrieves a compiler flag value and parses it as a Bool. Recognizes "true", "1" as true, everything else as false.
Example:
var debugMode = DefinesMacro.getBoolDefine("debug_mode"); // true
Name | Type | Description |
---|---|---|
key |
Dynamic | The name of the compiler flag |
Returns | Description |
---|---|
Dynamic | Expression containing the parsed boolean value |
Checks if a compiler flag is defined (regardless of its value).
Example:
if (DefinesMacro.isDefined("ceramic_use_arcade")) {
// Arcade physics is enabled
}
Name | Type | Description |
---|---|---|
key |
Dynamic | The name of the compiler flag |
Returns | Description |
---|---|
Dynamic | Expression containing true if defined, false otherwise |
getDefines(): Dynamic
Retrieves a map of all defined compiler flags and their values. Useful for debugging or conditional compilation based on multiple flags.
Example:
var allDefines = DefinesMacro.getDefines();
for (key => value in allDefines) {
trace('$key = $value');
}
Returns | Description |
---|---|
Dynamic | Expression containing a Map<String,String> of all defines |