@:build() an abstract class' fields

52 views
Skip to first unread message

clemos

unread,
Jul 5, 2014, 9:40:20 AM7/5/14
to haxe...@googlegroups.com
Hi list,

I'm currently trying to clean-up a macro I wrote to support @:native on var names in js :

I managed to make it work using a typedef / MacroType that generates an abstract using defineType.

Now I'd like to simplify the macro to a @:build macro on an abstract definition, such as this:
@:build(util.NativeMap.buildFields())
abstract Options({
  @:native("some-option")
  var someOption : String;
}){}

The build macro should automatically create the abstract constructor, and get/set properties to convert the field name from "someOption" to "some-option", pretty much like it does here :

My problem is, it seems impossible to create instance methods on abstract at macro time.
The compiler throws :
Cannot access this from a static function

My understanding is that the build macro is executed at a time when the abstract have already been converted to an "abstract implementation".
The methods declared directly normally in an abstract are indeed already transformed to static, 'this' being the first argument. These methods seem to be also tagged with an @:impl metadata.
So I tried to define the abstract methods this way in my macro, but without luck...

Any way, is this an actual bug, or is there an alternative way of building abstract using macros (besides declaring types using defineType) ?

Best,
Clément

clemos

unread,
Jul 8, 2014, 6:09:34 AM7/8/14
to haxe...@googlegroups.com
anyone ?

clemos

unread,
Jul 8, 2014, 7:45:21 AM7/8/14
to haxe...@googlegroups.com
Ok nevermind, I've found an answer :
Reply all
Reply to author
Forward
0 new messages