What am I doing wrong with this simple macro code insertion?

31 views
Skip to first unread message

Dion Whitehead Amago

unread,
Aug 19, 2016, 2:15:40 PM8/19/16
to Haxe
The following simple code example gives me:

./Test.hx:8: characters 8-18 : Unknown identifier : inputValue

However, the macro block should be inserting that value inside "main()". What am I doing wrong?

//Test.hx

import haxe.macro.Context;

class Test
{
    static function main()
    {
        TestMacro.buildTestContent();
        inputValue = 'some other value' + Math.random();
        // trace(inputValue);
    }
}

class TestMacro
{
    public static macro function buildTestContent()
{
return macro {
var inputValue :String = 'sdfsdf';
trace('inside macro 1 ' + inputValue);
};
}
}

//build.hxml
-main Test
-cp .
-js Test.js

Skial Bainn

unread,
Aug 19, 2016, 2:45:55 PM8/19/16
to haxe...@googlegroups.com

Try adding `@:mergeBlock` after the macro keyword to see if that works.

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Alexander Kuzmenko

unread,
Aug 19, 2016, 4:17:33 PM8/19/16
to Haxe
Your inputValue is only visible in a scope of a block you generated. Add @:megeBlock as Simn suggested to merge your generated block to a scope of parent block.

пятница, 19 августа 2016 г., 21:15:40 UTC+3 пользователь Dion Whitehead Amago написал:
Reply all
Reply to author
Forward
0 new messages