Haxe Code Cookbook

expression macro

Overview of Haxe code snippets, examples and tutorials tagged with expression macro.

  • Jan 03, 2017 Macros /

     git expression-macro process

    This example executes a process on the system, compile-time. This allows to run a git command git rev-parse HEAD and use its result as the value.‥

  • Jan 03, 2017 Macros /

     expression-macro building-fields

    This macro function automatically assigns parameters of method to local variables.‥

  • Jan 03, 2017 Macros /

     expression-macro validation

    Sometimes failed assertion checks make it difficult to tell what went wrong. For debugging the programmer not only wants to know that a check failed, but also why it failed. This macro outputs the values of all sub-expressions.‥

  • Jan 03, 2017 Macros /

     expression-macro

    Haxe makes it easy to define extensions for a typedef, but there is no easy way to combine the values of two or more structures to one, like {a:2} and {b:foo} to {a:2,b:foo}. The following macro does this for you.‥

  • Jan 03, 2017 Macros /

     enum expression-macro

    The following macro function returns an array of all possible values of a given @:enum abstract type. Since it's not possible in runtime (because abstracts doesn't exist there), we need to use a macro for that.‥

  • Jan 03, 2017 Macros /

     enum pattern-matching expression-macro

    Sometimes we have an instance of enum that is of known constructor (or we only accept that constructor) and we want to extract values from that instance. Normally, to do this, we have to use pattern matching (switch), however it's quite verbose, so we can instead use this macro static extension method that will generate switch for us.‥

  • Jan 03, 2017 Macros /

     expression-macro

    This example shows:‥

  • Jan 03, 2017 Macros /

     conditional-compilation expression-macro

    This snippet demonstrates how to get, set, check for, and list compiler flags.‥

  • Jul 04, 2017 Macros /

     build-macro building-fields expression-macro

    This example lets you take a file next to the current module .hx file and include its file content. That can be very useful if you want to separate (for example) view templates, shader sources or other multiline texts from the Haxe source. The articles demonstrates how to do it with an expression macro but also with a build macro.‥

  • Jan 03, 2017 Macros /

     json validation expression-macro

    Json is quite a strict format. Ensure all comma's and quotes are correct using a macro function, which is executed while compiling.‥