Find about object's attributes and methods during runtime

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

Find about object's attributes and methods during runtime

Thomas-8
Hi, what method is available to me to discover which attributes and
methods an object has during runtime. I want to do something like:

trace(object.methods());
trace(object.attributes());

And that would display stuff for me to play with. is that possible?

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

Re: Find about object's attributes and methods during runtime

Nathan Rixham
Thomas wrote:
> Hi, what method is available to me to discover which attributes and
> methods an object has during runtime. I want to do something like:
>
> trace(object.methods());
> trace(object.attributes());
>
> And that would display stuff for me to play with. is that possible?
>

partially afaik, not sure about getting methods but you can get fields -
somebody who actually knows will be able to help more, main class is

http://haxe.org/api/reflect

a quick google for haxe reflect or haxe reflection should get some
initial pointers if nobody else replies quickly.

regards

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

Re: Find about object's attributes and methods during runtime

Nathan Rixham
In reply to this post by Thomas-8
Thomas wrote:
> Hi, what method is available to me to discover which attributes and
> methods an object has during runtime. I want to do something like:
>
> trace(object.methods());
> trace(object.attributes());
>
> And that would display stuff for me to play with. is that possible?
>

and here's the rest..

http://haxe.org/api/type

seems v full featured :D another +++ for haXe in my book (ps worth
clicking round the api, a wealth of classes in there)

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

Re: Find about object's attributes and methods during runtime

Hudson Ansley
In reply to this post by Thomas-8
http://haxe.org/api/reflect

should have its own entry in "language features" or "language
reference" pages, imo

Regards,
Hudson

On Mon, Jun 8, 2009 at 5:09 PM, Thomas<[hidden email]> wrote:

> Hi, what method is available to me to discover which attributes and
> methods an object has during runtime. I want to do something like:
>
> trace(object.methods());
> trace(object.attributes());
>
> And that would display stuff for me to play with. is that possible?
>
> --
> 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
|

Find about object's attributes and methods during runtime

Blue Sans douze
In reply to this post by Thomas-8
I know there is Reflect for attributes

Try :
trace(Reflect.fields(object));

More on
http://www.haxe.org/api/reflect

Toc.
--Blue112


2009/6/8 Thomas <[hidden email]>
Hi, what method is available to me to discover which attributes and
methods an object has during runtime. I want to do something like:

trace(object.methods());
trace(object.attributes());

And that would display stuff for me to play with. is that possible?

--
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: Find about object's attributes and methods during runtime

David Bergman
In reply to this post by Nathan Rixham
Just note that haXe's runtime view of the world is a bit different  
than its compile-time view. Specifically w.r.t. attributes.

/David

On Jun 8, 2009, at 5:20 PM, Nathan Rixham wrote:

> Thomas wrote:
>> Hi, what method is available to me to discover which attributes and
>> methods an object has during runtime. I want to do something like:
>> trace(object.methods());
>> trace(object.attributes());
>> And that would display stuff for me to play with. is that possible?
>
> and here's the rest..
>
> http://haxe.org/api/type
>
> seems v full featured :D another +++ for haXe in my book (ps worth  
> clicking round the api, a wealth of classes in there)
>
> --
> 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: Find about object's attributes and methods during runtime

James W. Hofmann
In reply to this post by Thomas-8
Quoting Thomas <[hidden email]>:

> Hi, what method is available to me to discover which attributes and
> methods an object has during runtime. I want to do something like:
>
> trace(object.methods());
> trace(object.attributes());
>
> And that would display stuff for me to play with. is that possible?
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

The following is from memory and untested:

for (f in Reflect.fields(obj))
{
    var field = Reflect.field(obj,f);
    if (Reflect.isFunction(field))
          trace(f+" is a function");
    else
          trace(f+" is a variable");
}

If you want to examine types:

import Type; // you need this to access ValueType

for (f in Reflect.fields(obj))
{
    var fieldtype = Type.typeof(Reflect.field(obj,f));
    if (fieldtype==ValueType.TObject)
        trace(f+" is an Object");
    if (fieldtype==ValueType.TInt)
        trace(f+" is an Int");
    // ... etc.
}

If you want a more complex example get xreflect from haxelib, it uses  
Reflect to construct entire data structures at runtime.


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

Re: Find about object's attributes and methods during runtime

Ian Martins
In reply to this post by Thomas-8
Thomas wrote:
> Hi, what method is available to me to discover which attributes and
> methods an object has during runtime. I want to do something like:
>
> trace(object.methods());
> trace(object.attributes());
>
> And that would display stuff for me to play with. is that possible?
>
>  
http://haxe.org/doc/cross/reflect

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

Re: Find about object's attributes and methods during runtime

Thomas-8
In reply to this post by James W. Hofmann
Thank you very much for the links, I was struggling to find my way
through the API.

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

Re: Find about object's attributes and methods during runtime

jlm@justinfront.net
In reply to this post by Nathan Rixham
An example of using reflect can be found in my class here
http://code.google.com/p/facebridgex/source/browse/trunk/facebridgex/FacebookExample.hx
not sure if helps.

;j

On 8 Jun 2009, at 22:18, Nathan Rixham wrote:

> Thomas wrote:
>> Hi, what method is available to me to discover which attributes and
>> methods an object has during runtime. I want to do something like:
>> trace(object.methods());
>> trace(object.attributes());
>> And that would display stuff for me to play with. is that possible?
>
> partially afaik, not sure about getting methods but you can get  
> fields - somebody who actually knows will be able to help more, main  
> class is
>
> http://haxe.org/api/reflect
>
> a quick google for haxe reflect or haxe reflection should get some  
> initial pointers if nobody else replies quickly.
>
> regards
>
> --
> 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: Find about object's attributes and methods during runtime

go2ghana
In reply to this post by Nathan Rixham
Nathan Rixham schrieb:
Thomas wrote:
Hi, what method is available to me to discover which attributes and
methods an object has during runtime. I want to do something like:

trace(object.methods());
trace(object.attributes());

And that would display stuff for me to play with. is that possible?


partially afaik, not sure about getting methods but you can get fields - somebody who actually knows will be able to help more, main class is

http://haxe.org/api/reflect

a quick google for haxe reflect or haxe reflection should get some initial pointers if nobody else replies quickly.

regards

Hi,
afaik you need to use rtti to get runtime instance methods:

http://haxe.org/doc/advanced/rtti

Axel

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