Macro @:build, @:autobuild and @:macro questions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro @:build, @:autobuild and @:macro questions

Nemea Lion
Hi

I'm currently using the new macro system from the nightly builds, and have a few questions.

It seems you can't use @:build or @:autobuild togheter with @:macro method invocation

Example:

MyMacroClass.hx    <-- Where I have my @:macro methods

MyEnum.hx    <-- this one has @:build with MyMacroClass.myEnumBuilder();
MyOtherClass.hx    <-- Here I generate some code with MyMacroClass.someOtherFunction(), (not using @:build)

And finally

MyFinalClass.hx <--- Here I'll use MyEnum and MyOtherClass.

However I cannot compile this, as it says:
You can't access the neko package with current compilation flags (for neko.io.File)  for file MyMacroClass

(All non-macro classes are for flash.)

It seems that if I use a class with @:build or @:autobuild and then use some macro functions in the same project
the compiler only does the @:build part, and then tries to do the other macro invocation during normal compilation.
If I only use one of them, it's fine.

Also, Context.getLocalClass behaves diferently depending if you use @:build or @:autobuild,
when constructing MyEnum, I want to access some metadata I declared on it, however, If I use @:build,
Context.getLocalClass() returns a reference to MyFinalClass (who is importing MyEnum), but If I use @:autobuild, it
points to MyEnum.

Anyone can explain macro process in a little more detail?

Carlos Delgado


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Macro @:build, @:autobuild and @:macro questions

Nicolas Cannasse
Le 07/07/2011 17:43, Nemea Lion a écrit :
> Hi
>
> I'm currently using the new macro system from the nightly builds, and
> have a few questions.
>
> It seems you can't use @:build or @:autobuild togheter with @:macro
> method invocation

@:build and @:autobuild calls are already running in "macro mode" so you
can directly call methods that don't have @:macro

> However I cannot compile this, as it says:
> You can't access the neko package with current compilation flags (for
> neko.io.File)  for file MyMacroClass

It seems that MyMacroClass is referenced from outside the macro mode,
you can try to add #if macro .... #end around all the methods that are
not @:macro

BTW I find the distinction between macro-mode and platform-mode a bit
hard to understand for people : if anyone has a better suggestion on how
to deal with it I'm open.

> Also, Context.getLocalClass behaves diferently depending if you use
> @:build or @:autobuild,
> when constructing MyEnum, I want to access some metadata I declared on
> it, however, If I use @:build,
> Context.getLocalClass() returns a reference to MyFinalClass (who is
> importing MyEnum), but If I use @:autobuild, it
> points to MyEnum.

Seems like a bug, could you post it on
http://code.google.com/p/haxe/issues ?

Thanks,
Nicolas

--
haXe - an open source web programming language
http://haxe.org