8000 Update assets/content/cookbook/Macros/strictly-typed-json.md · HaxeFoundation/code-cookbook@7206b5e · GitHub
[go: up one dir, main page]

Skip to content

Commit 7206b5e

Browse files
haxiomicAurel300
andauthored
Update assets/content/cookbook/Macros/strictly-typed-json.md
Co-authored-by: Aurel <Aurel300@users.noreply.github.com>
1 parent 06d28e8 commit 7206b5e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

assets/content/cookbook/Macros/strictly-typed-json.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ for (i in leveldata.array) { // works now because we know the type of the leveld
3636

3737
**Explanation**: We run the original `Json.parse(File.getContent())` snippet in a macro function so it will execute when Haxe compiles our calls to `JsonMacro.load()`. Instead of returning the JSON object, in macros we need to return _syntax_. So we must convert our JSON object into Haxe syntax – just as if we'd typed our JSON out manually as Haxe objects. Fortunately there's a built-in operator for converting values into Haxe syntax, it's the ['macro-reification-value-operator': `$v{ some-basic-value }`](https://haxe.org/manual/macro-reification-expression.html). We could also use [`Context.makeExpr(value, position)`](https://api.haxe.org/haxe/macro/Context.html#makeExpr) to do the same job. We wrap the JSON reading in a `try-catch` so we can tidy-up error reporting a little.
3838

39-
With this approach, the JSON's content is embedded into your compiled app and _not_ loaded at runtime, therefore, the path argument must be a constant string and cannot be an expression evaluated at runtime.
39+
With this approach, the JSON's content is embedded into your compiled program and _not_ loaded at runtime, therefore, the path argument must be a constant string and cannot be an expression evaluated at runtime.
4040

4141
> Author: [George Corney](https://github.com/haxiomic)

0 commit comments

Comments
 (0)
0