SRL Archive - Suggestions

toStr() formatting options


Gu3st...

2013-04-01 14:34:35

I think a good addition would be to have formatting options to the current toStr() function.
It shouldn't be too hard to add, either; maybe I'll get around to add it myself, but I'll most likely just end up making a function in a script instead..

Immagine doing toStr(Object, JSON); that would output the type "Object" in JSON format, or toStr(Object, XML) for XML format. I think it would be a nice addition; will make it easier to create databases and such for Simba.

E: Much harderA bit harder to make a script in Simba for this, if any of the variables contain a curly or square bracket…

Brandon

2013-04-02 16:43:21

That means that there'd be a ton of to_string overloads because I'm sure it'll lead to other members wanting to_string for a ton of other stuff that may not be a good idea?

Also, if Object is a polymorphic type (which I assume it is due to the other languages out there that make it so), how will simba know what variables are contained within Object? Or is object a specific type?

Gu3st...

2013-04-02 21:00:13

Just support one and then let the scripters do the rest?
Support one human-readable and one binary structure (i.e XML and Binary-XML) and you're done.

The problem comes when the user wants to set all the values of the object to the object they're using.
They would have to do it manually, but it's still good for when you want to save to an online database that can parse i.e JSON (using JavaScript, this is really easy).

Adding several data structures is trivial. JSON and XML would be nice, but only XML is good.
Eventually we might support other types, but XML should be enough for everyone, for now.

http://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats for a list of viable data formats.

masterBB

2013-04-03 07:48:09

How does simba knows what properties of the object needs to be stored? How does simba knows which part of the object is the unique identifier?

eg

type 
TApple = record of
taste: String;
size: LongWord;
end;

var
RedApple, GreenApple: TApple;

...

begin
RedApple.taste := "sweet";
RedApple.size := 3;

GreenApple.taste := "sour";
GreenApple.size := 5;

ToStr(RedApple, XMLFormat);
ToStr(GreenApple, XMLFormat);

ToStr([RedApple, GreenApple], XMLFormat);
end;

output:

<apple>
<taste>sweet</taste>
<size>3</size>
</apple>

<apple>
<taste>sour</taste>
<size>5</size>
</apple>

<apples>
<apple>
<taste>sweet</taste>
<size>3</size>
</apple>

<apple>
<taste>sour</taste>
<size>5</size>
</apple>
</apples>

Gu3st...

2013-04-03 13:20:33

Why do you guys want to make this so hard?
The toStr() already follows some formatting rules, all I'm suggesting is some new rules.
@masterBB;
type 
TApple = record of
color: String;
taste: String;
size: LongWord;
end;

var
RedApple, GreenApple: TApple;

...

begin
RedApple.taste := "sweet";
RedApple.Color := 'Red';
RedApple.size := 3;

GreenApple.taste := "sour";
GreenApple.Color := 'Green';
GreenApple.size := 5;

ToStr(RedApple, XMLFormat);
ToStr(GreenApple, XMLFormat);

ToStr([RedApple, GreenApple], XMLFormat);
end;

masterBB

2013-04-03 14:27:37

From: Zyt3x
Why do you guys want to make this so hard?
The toStr() already follows some formatting rules, all I'm suggesting is some new rules.


But those rules are in lape/pascalscript. Hmmm, feel free to add them though, I am of no help there :S