SRL Archive - Development

Added all type -> string conversions, and I mean *all*.


mastaraymond

2010-01-18 08:16:46

So Wizzup is against this, but I think it's pro.. PS has a method somewhere that allows you to convert basically any datatype to a string, even ones created during runtime! So this might be a bit hackish, but It's definitely awesum!

program new;
type
LetsDoThis = record
str : string;
x,y : integer;
end;
LetsDoThis2 = record
str : string;
pt : TPoint;
end;
Yeah = array of LetsDoThis2;
ArrThis = array of yeah;


var
x : LetsDoThis;
y : arrthis;
j : TForm;
i,ii : integer;
begin
x.str := 'Testmebitch';
x.x := 500;
x.y := -900;
Writeln(x);
SetLength(y,2);
for i := 0 to high(y) do
begin;
setlength(y[i],2);
for ii := 0 to high(y[i]) do
begin;
y[i][ii].pt := Point(i*5,-random(9000));
y[i][ii].str := format('[%d][%d]=%s',[i,ii,tostr(y[i][ii].pt)]);
end;
end;
Writeln(y);
Writeln(TPointArray([Point(5,5),Point(20,1337),point(1,2)]));
J := TForm.Create(nil);
Writeln(j.canvas);
end.

Output:
Compiled succesfully in 16 ms.
('Testmebitch', 500, -900)
[[('[0][0]=(0, -8379)', (0, -8379)), ('[0][1]=(0, -3182)', (0, -3182))], [('[1][0]=(5, -7787)', (5, -7787)), ('[1][1]=(5, -6094)', (5, -6094))]]
[(5, 5), (20, 1337), (1, 2)]
TControlCanvas
Succesfully executed

Dan Cardin

2010-01-18 09:34:28

would be nifty if you could convert them back.

mastaraymond

2010-01-18 10:14:34

From: Dan Cardin
would be nifty if you could convert them back.

What use would that have?

This is for debuggin purposes obviously..

R0b0t1

2010-01-19 09:10:56

Serialization.

Smartzkid

2010-01-31 15:34:11

For once in my life, I ditto R0b0t.

I definitely like this for ease of debugging; its a pain to have to write a tostring method just to debug one or two objects.

nielsie95

2010-02-23 07:22:18

Would be nice if sets worked too (to integer). Converting back would indeed be totally awesome) :)

Nava2

2010-03-13 20:54:55

Is this exported to PS? The actual ``toString()'' method?

e: nvm found it, toStr().

Wizzup?

2010-03-14 07:36:28

From: nielsie95
Would be nice if sets worked too (to integer). Converting back would indeed be totally awesome) :)


Not sure how you would do that with structures though…?

nielsie95

2010-03-14 08:42:52

If you know what type the field is, you should know the size (and offset) so it shouldn't be that hard?

Wizzup?

2010-03-14 08:58:49

From: nielsie95
If you know what type the field is, you should know the size (and offset) so it shouldn't be that hard?


Yes, but how will you know the type? You'd have to writeln the type as well in that case.

nielsie95

2010-03-14 09:03:13

I'm afraid so :\

Dan Cardin

2010-03-14 14:11:23

but then you'd be able to create entire complex structures from strings!

MasterKill

2010-03-14 14:23:52

I do also think it's pro, good job raymond! And yes it would be very handy if ints get like auto converted in writeln, like php does :)
WriteLn('Loads mined: ' + LoadsInt);

Nava2

2010-03-14 14:32:15

OOP supports this, but it would involve how PS interprets strings which would involve haxing PS, perhaps Ben will change this in his interpretor.

nielsie95

2010-03-14 14:44:28

From: Dan Cardin
but then you'd be able to create entire complex structures from strings!


Not really, as you still need to be able to access it and the memory will have to be allocated beforehand.

From: Nava2
OOP supports this, but it would involve how PS interprets strings which would involve haxing PS, perhaps Ben will change this in his interpretor.


I think you mean operator overloading. That doesn't necessarily have to involve OOP..

Nava2

2010-03-14 17:11:55

Would it be operator overloading though? I mean, I guess we could set it up..

Since we already overload the +/- operator for TPoints.

Wizzup?

2010-03-14 17:31:44

From: Nava2
Would it be operator overloading though? I mean, I guess we could set it up..

Since we already overload the +/- operator for TPoints.


No, we don't overload that. Only internally.

Dan Cardin

2010-03-14 21:15:49

From: nielsie95
Not really, as you still need to be able to access it and the memory will have to be allocated beforehand.
twas more i meant, being a steam lined with already declared variables rather than having to do it all separately, if i quite understand what we're talking about.