Created
June 1, 2015 07:57
-
-
Save back2dos/8f69fe87a5fa03c5709e to your computer and use it in GitHub Desktop.
Macro context vs. output context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Original source code: | |
| class Main { | |
| #if !macro | |
| static function main() { | |
| test(); | |
| } | |
| #end | |
| macro static function test() { | |
| return makeHelloWorld(); | |
| } | |
| #if macro | |
| static function makeHelloWorld() { | |
| return macro trace('hello world'); | |
| } | |
| #end | |
| } | |
| //As seen from macro context | |
| class Main { | |
| macro static function test() { | |
| return makeHelloWorld(); | |
| } | |
| static function makeHelloWorld() { | |
| return macro trace('hello world'); | |
| } | |
| } | |
| //As seen in the output context | |
| class Main { | |
| static function main() { | |
| test(); | |
| } | |
| macro static function test(); | |
| } | |
| //After macro evaluation | |
| class Main { | |
| static function main() { | |
| trace('hello world');//this is what was returned by Main.test() called in macro context | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More info here: http://haxe.org/manual/macro-compilation-role.png