specializing Std.string()?

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

specializing Std.string()?

Raoul Duke
hi,

what/is there a canonical way for me to make my own objects support
Std.string(), so they generate a custom string?

ah!! i just tried toString() and it worked. this doesn't seem to be
documented anywhere that i noticed yet :-)

thanks.

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

Re: specializing Std.string()?

Benjamin Dasnois
Hi,

As far as I know this is not a specification that Std.string will call the object's toString function. Nicolas, any thought about that? Should a target implement that to be "compliant"? Having had a look at the code before I do remember that this is the case, but Raoul is right, it's not specified anywhere. That should certainly be the case.

Regards,

On Sun, Sep 5, 2010 at 12:13 AM, Raoul Duke <[hidden email]> wrote:
hi,

what/is there a canonical way for me to make my own objects support
Std.string(), so they generate a custom string?

ah!! i just tried toString() and it worked. this doesn't seem to be
documented anywhere that i noticed yet :-)

thanks.

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



--
DASNOIS Benjamin
http://www.benjamindasnois.com

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

Re: specializing Std.string()?

Nicolas Cannasse
Le 05/09/2010 00:26, Benjamin Dasnois a écrit :
> Hi,
>
> As far as I know this is not a specification that Std.string will call
> the object's toString function. Nicolas, any thought about that? >Should
> a target implement that to be "compliant"?

There are no strong specifications on how objects should be String'ified
so far, but toString() works on a all platforms as far as I know, and I
guess we could make it a requirement for haXe cross platform compatibility.

Nicolas

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

Re: specializing Std.string()?

Benjamin Dasnois
That makes sense.
If you're ok with it Nicolas, I'll be having a look at how things are implemented across targets for all kind of objects (I believe it works exactly the same way on all platforms ATM), and write a doc "Object stringification" in the language spec.

On Sun, Sep 5, 2010 at 12:43 AM, Nicolas Cannasse <[hidden email]> wrote:
Le 05/09/2010 00:26, Benjamin Dasnois a écrit :

Hi,

As far as I know this is not a specification that Std.string will call
the object's toString function. Nicolas, any thought about that? >Should
a target implement that to be "compliant"?

There are no strong specifications on how objects should be String'ified so far, but toString() works on a all platforms as far as I know, and I guess we could make it a requirement for haXe cross platform compatibility.

Nicolas

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



--
DASNOIS Benjamin
http://www.benjamindasnois.com

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

Re: specializing Std.string()?

Nicolas Cannasse
Le 05/09/2010 00:55, Benjamin Dasnois a écrit :
> That makes sense.
> If you're ok with it Nicolas, I'll be having a look at how things are
> implemented across targets for all kind of objects (I believe it works
> exactly the same way on all platforms ATM), and write a doc "Object
> stringification" in the language spec.

Sure ! First summing up the current status then deciding which goes into
the specification and which doesn't seems like a good idea.

Nicolas

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

Re: specializing Std.string()?

Gamehaxe
Currently, cpp differs from neko in that it does not print the members for
a "Normal" class, just the class name. (But it does print all for  
Anonymous objects).

With neko, it was (have not checked in a while) quite easy to overflow the
stack when tracing a class with a circular reference.
Something to think about.

Hugh


> Le 05/09/2010 00:55, Benjamin Dasnois a écrit :
>> That makes sense.
>> If you're ok with it Nicolas, I'll be having a look at how things are
>> implemented across targets for all kind of objects (I believe it works
>> exactly the same way on all platforms ATM), and write a doc "Object
>> stringification" in the language spec.
>
> Sure ! First summing up the current status then deciding which goes into  
> the specification and which doesn't seems like a good idea.
>
> Nicolas

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

Re: specializing Std.string()?

Benjamin Dasnois
This is something that could easily be worked around by using a max depth. Just let me finish writing n the current state and we will discuss it :)

On Sun, Sep 5, 2010 at 5:32 PM, Hugh Sanderson <[hidden email]> wrote:
Currently, cpp differs from neko in that it does not print the members for
a "Normal" class, just the class name. (But it does print all for Anonymous objects).

With neko, it was (have not checked in a while) quite easy to overflow the
stack when tracing a class with a circular reference.
Something to think about.

Hugh



Le 05/09/2010 00:55, Benjamin Dasnois a écrit :
That makes sense.
If you're ok with it Nicolas, I'll be having a look at how things are
implemented across targets for all kind of objects (I believe it works
exactly the same way on all platforms ATM), and write a doc "Object
stringification" in the language spec.

Sure ! First summing up the current status then deciding which goes into the specification and which doesn't seems like a good idea.

Nicolas

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



--
DASNOIS Benjamin
http://www.benjamindasnois.com

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

Re: specializing Std.string()?

Pimm Hogeling
In reply to this post by Gamehaxe
On 5 September 2010 17:32, Hugh Sanderson <[hidden email]> wrote:
With neko, it was (have not checked in a while) quite easy to overflow the
stack when tracing a class with a circular reference.
Something to think about.

Hugh
True. We've fixed this for arrays and lists with a circular reference in MLC (source).

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