macro, ExprDef of Class<T> ?

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

macro, ExprDef of Class<T> ?

Lars Madson
Hi

I'm starting with macros, what would be the type of a Class<T> in macros
ExprDef ?

I'm doing

aclass.all( db.Object )   as a static macro function:

@:macro public static function all( e : Expr ) : Expr {
         switch( e.expr ) {
             case  ??
         }
     }

thx
Laurent

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

Re: macro, ExprDef of Class<T> ?

Simon Krajewski
  trace works in macros, so just trace(e.expr) and see what you get.
Should be some combination of EField and EType.

Regards
Simon

Am 15.12.2010 19:02, schrieb Laurent Kappler:

> Hi
>
> I'm starting with macros, what would be the type of a Class<T> in
> macros ExprDef ?
>
> I'm doing
>
> aclass.all( db.Object )   as a static macro function:
>
> @:macro public static function all( e : Expr ) : Expr {
>         switch( e.expr ) {
>             case  ??
>         }
>     }
>
> thx
> Laurent
>

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

macro, how to resolveClass( "Class<T>" ) before compiled?

Lars Madson

I got further, getting a string of the expr input.
Now I'm trying to resolve that Class<T> using Type.resolveClass( string
), which return null.

Not a surprise as that class should be compiled to be resolved.
I would like to list fields of Class<T> to retreive their type and field
name, how should I do that using macro?

thx
Laurent


Le 15/12/2010 19:14, Simon Krajewski a écrit :

>  trace works in macros, so just trace(e.expr) and see what you get.
> Should be some combination of EField and EType.
>
> Regards
> Simon
>
> Am 15.12.2010 19:02, schrieb Laurent Kappler:
>> Hi
>>
>> I'm starting with macros, what would be the type of a Class<T> in
>> macros ExprDef ?
>>
>> I'm doing
>>
>> aclass.all( db.Object )   as a static macro function:
>>
>> @:macro public static function all( e : Expr ) : Expr {
>>         switch( e.expr ) {
>>             case  ??
>>         }
>>     }
>>
>> thx
>> Laurent
>>
>


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

Re: macro, how to resolveClass( "Class<T>" ) before compiled?

Nicolas Cannasse
Le 16/12/2010 15:13, Laurent Kappler a écrit :
>
> I got further, getting a string of the expr input.
> Now I'm trying to resolve that Class<T> using Type.resolveClass( string
> ), which return null.
>
> Not a surprise as that class should be compiled to be resolved.
> I would like to list fields of Class<T> to retreive their type and field
> name, how should I do that using macro?

Use haxe.macro.Context.getType("my.pack.MyClass")

Nicolas

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

Re: macro, how to access values of static fields?

Lars Madson
sweet.
Now I'm trying to access the values of that db.Object.PRIVATE_FIELDS array.

I got this:
                             var MType = Context.getType( s + '.' + f );
                                 switch( MType ) {
                                     case TInst( t, p ):
                                         var statics =
t.get().statics.get();
                                         for ( s in statics )
                                             trace( s );
                                     default:
                                 }

which returns stuff like this:

{
meta => { remove => #function:1, add => #function:2, get => #function:0 },
isPublic => false,
type => TInst(Array,[TInst(String,[])]),
name => PRIVATE_FIELDS,
params => []
},

I guess params would contain those values if the field was initiated?

Should I use metadata to write those values in? I would prefer not to.

Macros rocks!
Thank you!
Laurent





Le 16/12/2010 15:16, Nicolas Cannasse a écrit :

> Le 16/12/2010 15:13, Laurent Kappler a écrit :
>>
>> I got further, getting a string of the expr input.
>> Now I'm trying to resolve that Class<T> using Type.resolveClass( string
>> ), which return null.
>>
>> Not a surprise as that class should be compiled to be resolved.
>> I would like to list fields of Class<T> to retreive their type and field
>> name, how should I do that using macro?
>
> Use haxe.macro.Context.getType("my.pack.MyClass")
>
> Nicolas
>


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

Re: macro, how to access values of static fields?

Franco Ponticelli
You can't read the assigned values since that is something known only at runtime ... you have to figure out an alternative. My 2 cents is that now that we have macros and metadatas we should reconsider how SPOD is done and re-implement. Not something I have time for at the moment, but indeed an interesting project.

Franco.

On Thu, Dec 16, 2010 at 3:34 PM, Laurent Kappler <[hidden email]> wrote:
sweet.
Now I'm trying to access the values of that db.Object.PRIVATE_FIELDS array.

I got this:
                           var MType = Context.getType( s + '.' + f );
                               switch( MType ) {
                                   case TInst( t, p ):
                                       var statics = t.get().statics.get();
                                       for ( s in statics )
                                           trace( s );
                                   default:
                               }

which returns stuff like this:

{
meta => { remove => #function:1, add => #function:2, get => #function:0 },
isPublic => false,
type => TInst(Array,[TInst(String,[])]),
name => PRIVATE_FIELDS,
params => []
},

I guess params would contain those values if the field was initiated?

Should I use metadata to write those values in? I would prefer not to.

Macros rocks!
Thank you!
Laurent





Le 16/12/2010 15:16, Nicolas Cannasse a écrit :
Le 16/12/2010 15:13, Laurent Kappler a écrit :

I got further, getting a string of the expr input.
Now I'm trying to resolve that Class<T> using Type.resolveClass( string
), which return null.

Not a surprise as that class should be compiled to be resolved.
I would like to list fields of Class<T> to retreive their type and field
name, how should I do that using macro?

Use haxe.macro.Context.getType("my.pack.MyClass")

Nicolas



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


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

Re: macro, how to access values of static fields?

Lars Madson
I will alternatively use some metadata for now. :)

Laurent


Le 16/12/2010 16:41, Franco Ponticelli a écrit :
You can't read the assigned values since that is something known only at runtime ... you have to figure out an alternative. My 2 cents is that now that we have macros and metadatas we should reconsider how SPOD is done and re-implement. Not something I have time for at the moment, but indeed an interesting project.

Franco.

On Thu, Dec 16, 2010 at 3:34 PM, Laurent Kappler <[hidden email]> wrote:
sweet.
Now I'm trying to access the values of that db.Object.PRIVATE_FIELDS array.

I got this:
                           var MType = Context.getType( s + '.' + f );
                               switch( MType ) {
                                   case TInst( t, p ):
                                       var statics = t.get().statics.get();
                                       for ( s in statics )
                                           trace( s );
                                   default:
                               }

which returns stuff like this:

{
meta => { remove => #function:1, add => #function:2, get => #function:0 },
isPublic => false,
type => TInst(Array,[TInst(String,[])]),
name => PRIVATE_FIELDS,
params => []
},

I guess params would contain those values if the field was initiated?

Should I use metadata to write those values in? I would prefer not to.

Macros rocks!
Thank you!
Laurent





Le 16/12/2010 15:16, Nicolas Cannasse a écrit :
Le 16/12/2010 15:13, Laurent Kappler a écrit :

I got further, getting a string of the expr input.
Now I'm trying to resolve that Class<T> using Type.resolveClass( string
), which return null.

Not a surprise as that class should be compiled to be resolved.
I would like to list fields of Class<T> to retreive their type and field
name, how should I do that using macro?

Use haxe.macro.Context.getType("my.pack.MyClass")

Nicolas



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



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