Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   TGraalVar.toString (https://forums.graalonline.com/forums/showthread.php?t=134259883)

WhiteDragon 07-19-2010 09:51 PM

TGraalVar.toString
 
So it'd be possible to do something like this...
PHP Code:

temp.blah = new TStaticVar();
temp.blah.toString = function () {
  return 
"Hello";
};
echo(
temp.blah); // this would echo Hello 

This should also work in any case where you do something like (@temp.blah).



It would probably make most sense if by default toString was:
PHP Code:

temp.blah.toString = function () {
  return 
this.name;
}; 

This way there would be no "magic" happening when something gets cast to a string.

Also, this would mean more compatibility with JavaScript.

adam 07-19-2010 11:39 PM

RogueShadow approves this message.

Mark Sir Link 07-20-2010 05:07 PM

ya

Loriel 07-20-2010 07:24 PM

Man I don't know just introduce type classes or something

adam 07-20-2010 09:32 PM

Naturally, if we were to get toString there'd have to be toType for everything.

WhiteDragon 07-20-2010 09:46 PM

Let's keep it to stuff that may actually happen. (Provided the moons align.)

cbk1994 07-20-2010 09:47 PM

Wondering what you actually need this for?

WhiteDragon 07-20-2010 10:04 PM

For exactly what it is made for: providing a string alternative to an object.

obj.name can't be used in my case because the string would depend on certain properties of the object.

The current alternative is making an entirely separate function, but that approach gets very messy.

Inverness 07-22-2010 09:29 PM

Meh, I've been thinking of making a class to extend some basic GScript stuff. Might not look all pretty but it would get the job done. It would have stuff like a destroy function that checks if the object has onDestroyed() defined or so. It could have a toString() thing too. Was also thinking of adding functions for packing and unpacking variables from objects for passing my reference, etc.


All times are GMT +2. The time now is 03:42 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.