Re: macro questions (from dead code removal)

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

Re: macro questions (from dead code removal)

Simon Krajewski
Aha! So that's how it is supposed to be used. Suddenly macros seem to be way more powerful than before.

Is there any convenient way to iterate over "all (my) classes"? Making modifications based on metadata after Context.getType sounds like a lot of fun, but having to provide all relevant classes by hand is less appealing.

Thanks!
Simon

sorry for the slight off topic, but could you give a pointer to the "macros can add metadatas" topic? The macro and metadata pages on haxe.org don't mention this and I couldn't find any way of pulling it off.

You can obtain a type using Context.getType("pack.MyClass") ... it returns a TInst that contains a ref to ClassField that contains a field Meta. In that object you can use get/add/remove ... fields can have metas too ... and enum fields too :)
Documentation is not updated yet because they are not in any official release yet.

Franco 


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

Re: macro questions (from dead code removal)

Simon Krajewski
Another quick/question that just came to my mind: How about reverse indexing metadata so that a Macro could do something like haxe.rtti.Meta.getClasses("bindable") which returns an array of all classes (TInst objects) in the current compilation unit that have @bindable as metadata? Grouping classes like that would allow some interesting meta programming.

Regards
Simon

Am 14.12.2010 21:09, schrieb Simon Krajewski:
Aha! So that's how it is supposed to be used. Suddenly macros seem to be way more powerful than before.

Is there any convenient way to iterate over "all (my) classes"? Making modifications based on metadata after Context.getType sounds like a lot of fun, but having to provide all relevant classes by hand is less appealing.

Thanks!
Simon

sorry for the slight off topic, but could you give a pointer to the "macros can add metadatas" topic? The macro and metadata pages on haxe.org don't mention this and I couldn't find any way of pulling it off.

You can obtain a type using Context.getType("pack.MyClass") ... it returns a TInst that contains a ref to ClassField that contains a field Meta. In that object you can use get/add/remove ... fields can have metas too ... and enum fields too :)
Documentation is not updated yet because they are not in any official release yet.

Franco 


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

Re: macro questions (from dead code removal)

Franco Ponticelli
At the moment I think you can't do either, but indeed they could be really powerful additions to the macro armory.

Franco 

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

Re: macro questions (from dead code removal)

Nicolas Cannasse
In reply to this post by Simon Krajewski
Le 14/12/2010 21:40, Simon Krajewski a écrit :
> Another quick/question that just came to my mind: How about reverse
> indexing metadata so that a Macro could do something like
> haxe.rtti.Meta.getClasses("bindable") which returns an array of all
> classes (TInst objects) in the current compilation unit that have
> @bindable as metadata? Grouping classes like that would allow some
> interesting meta programming.

The issue that is that you can't currently list all the compiled classes
because macro execution is performed during compilation process, so all
classes might not be yet available or fully typed.

I'll add soon a way to register a callback that will get called when
compilation is finished. You'll not be able to add new classes at this
point but you'll be able to get all the classes that were compiled.

Nicolas

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

Re: macro questions (from dead code removal)

Simon Krajewski
  Hi Nicolas,

that sounds great. Could one of you give a short list of modifications
you can actually do to a class when executing a macro? Yesterday I
learned about editing metadata, how about class and instance fields?

In my current project I use Reflection to reassign instance methods so
they do something before/after their code execution. Can something like
that be done with Macros at some point?

Thanks!
Simon

Am 15.12.2010 09:30, schrieb Nicolas Cannasse:

> Le 14/12/2010 21:40, Simon Krajewski a écrit :
>> Another quick/question that just came to my mind: How about reverse
>> indexing metadata so that a Macro could do something like
>> haxe.rtti.Meta.getClasses("bindable") which returns an array of all
>> classes (TInst objects) in the current compilation unit that have
>> @bindable as metadata? Grouping classes like that would allow some
>> interesting meta programming.
>
> The issue that is that you can't currently list all the compiled
> classes because macro execution is performed during compilation
> process, so all classes might not be yet available or fully typed.
>
> I'll add soon a way to register a callback that will get called when
> compilation is finished. You'll not be able to add new classes at this
> point but you'll be able to get all the classes that were compiled.
>
> Nicolas
>

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

Re: macro questions (from dead code removal)

Nicolas Cannasse
Le 15/12/2010 14:26, Simon Krajewski a écrit :
> Hi Nicolas,
>
> that sounds great. Could one of you give a short list of modifications
> you can actually do to a class when executing a macro? Yesterday I
> learned about editing metadata, how about class and instance fields?
>
> In my current project I use Reflection to reassign instance methods so
> they do something before/after their code execution. Can something like
> that be done with Macros at some point?

So far you can only metadata. It is also possible to create "type
patches" that will apply as soon as the class is loaded and enable you
to modify a given class field/method-argument/method-return type. See
haxe/doc/extract.hxml+.patch for an usage example.

It will be possible soon to modify the "extern" flags of types, in order
to define which types get generated or not.

The ability to generate new methods/fields is currently not planned, I'm
waiting to see how/if it can be done elegantly given the lazy aspect of
the compiler (not mine)

Nicolas

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