mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-16 22:35:05 -05:00
Writeln now writeln's *EVERY* data type...
Made a ToStr that accepts *ANY* data type. See stringtest.mufa git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@426 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
8e617c9f35
commit
212e41ecd1
39
Tests/PS/stringtest.mufa
Normal file
39
Tests/PS/stringtest.mufa
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
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.
|
@ -67,28 +67,6 @@ begin;
|
|||||||
result.y2 := y2;
|
result.y2 := y2;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Capitalize(str : string) : string;
|
|
||||||
var
|
|
||||||
i , l : integer;
|
|
||||||
cap : boolean;
|
|
||||||
begin;
|
|
||||||
result := str;
|
|
||||||
l := length(str);
|
|
||||||
cap := true;
|
|
||||||
for i := 1 to l do
|
|
||||||
if cap and (str[i] in ['a'..'z'] + ['A'..'Z']) then
|
|
||||||
begin;
|
|
||||||
result[i] := UpperCase(str[i])[1];
|
|
||||||
cap := false;
|
|
||||||
end else if not (str[i] in ['a'..'z'] + ['A'..'Z']) then
|
|
||||||
cap := true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function psFormat(const fmt : string;const args : array of const) : string;
|
|
||||||
begin;
|
|
||||||
Result := Format(fmt,Args);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function Distance(x1, y1, x2, y2: Integer): Integer;
|
function Distance(x1, y1, x2, y2: Integer): Integer;
|
||||||
begin;
|
begin;
|
||||||
Result := Round(Sqrt(Sqr(x2-x1) + Sqr(y2-y1)));
|
Result := Round(Sqrt(Sqr(x2-x1) + Sqr(y2-y1)));
|
||||||
|
26
Units/MMLAddon/PSInc/Wrappers/strings.inc
Normal file
26
Units/MMLAddon/PSInc/Wrappers/strings.inc
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
function psFormat(const fmt : string;const args : array of const) : string;
|
||||||
|
begin;
|
||||||
|
Result := Format(fmt,Args);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function Capitalize(str : string) : string;
|
||||||
|
var
|
||||||
|
i , l : integer;
|
||||||
|
cap : boolean;
|
||||||
|
begin;
|
||||||
|
result := str;
|
||||||
|
l := length(str);
|
||||||
|
cap := true;
|
||||||
|
for i := 1 to l do
|
||||||
|
if cap and (str[i] in ['a'..'z'] + ['A'..'Z']) then
|
||||||
|
begin;
|
||||||
|
result[i] := UpperCase(str[i])[1];
|
||||||
|
cap := false;
|
||||||
|
end else if not (str[i] in ['a'..'z'] + ['A'..'Z']) then
|
||||||
|
cap := true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function psBoolToStr(bool : boolean) : string;
|
||||||
|
begin;
|
||||||
|
result := BoolToStr(bool,true);
|
||||||
|
end;
|
@ -22,7 +22,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddFunction(@ThreadSafeCall,'function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;');
|
AddFunction(@ThreadSafeCall,'function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;');
|
||||||
AddFunction(nil,'procedure writeln(s : string);'); //We use special function for this
|
AddFunction(nil,'procedure writeln(x);'); //We use special function for this
|
||||||
|
|
||||||
{ DTM }
|
{ DTM }
|
||||||
SetCurrSection('DTM');
|
SetCurrSection('DTM');
|
||||||
@ -96,8 +96,19 @@ AddFunction(@NewThreadCall,'function NewThreadCall(procname : string) : cardinal
|
|||||||
|
|
||||||
|
|
||||||
{string}
|
{string}
|
||||||
|
SetCurrSection('String');
|
||||||
AddFunction(@Capitalize,'function Capitalize(str : string) : string;');
|
AddFunction(@Capitalize,'function Capitalize(str : string) : string;');
|
||||||
AddFunction(@psFormat,'function Format(const fmt : string;const args : array of const) : string;');
|
AddFunction(@psFormat,'function Format(const fmt : string;const args : array of const) : string;');
|
||||||
|
AddFunction(nil,'function ToStr(x) : string;');
|
||||||
|
AddFunction(@IntToStr, 'function IntToStr(value: Integer): String;');
|
||||||
|
AddFunction(@FloatToStr, 'function FloatToStr(value: Extended): String;');
|
||||||
|
AddFunction(@psBoolToStr, 'function BoolToStr(value: Boolean): String;');
|
||||||
|
AddFunction(@StrToInt, 'function StrToInt(value: String): Integer;');
|
||||||
|
AddFunction(@StrToIntDef, 'function StrToIntDef(value: String; default: Integer): Integer;');
|
||||||
|
AddFunction(@StrToFloat, 'function StrToFloat(value: String): Extended;');
|
||||||
|
AddFunction(@StrToFloatDef, 'function StrToFloatDef(value: String; default: Extended): Extended;');
|
||||||
|
AddFunction(@StrToBool, 'function StrToBool(value: String): Boolean;');
|
||||||
|
AddFunction(@StrToBoolDef, 'function StrToBoolDef(value: String; default: Boolean): Boolean;');
|
||||||
|
|
||||||
{web}
|
{web}
|
||||||
SetCurrSection('Web');
|
SetCurrSection('Web');
|
||||||
|
@ -143,18 +143,31 @@ begin
|
|||||||
writeln(str);
|
writeln(str);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function MakeString(data : TPSVariantIFC) : string;
|
||||||
|
begin;
|
||||||
|
if data.aType.basetype in [btString,btChar] then
|
||||||
|
result := PSGetAnsiString(Data.Dta,data.aType)
|
||||||
|
else if data.aType.ExportName = 'BOOLEAN' then
|
||||||
|
result := BoolToStr(PSGetInt(Data.Dta,data.aType) <> 0,true)
|
||||||
|
else
|
||||||
|
result := PSVariantToString(data,'');
|
||||||
|
end;
|
||||||
|
|
||||||
function writeln_(Caller: TPSExec; p: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
|
function writeln_(Caller: TPSExec; p: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
|
||||||
var
|
var
|
||||||
arr: TPSVariantIFC;
|
arr: TPSVariantIFC;
|
||||||
begin
|
begin
|
||||||
Result:=true;
|
Result:=true;
|
||||||
arr:=NewTPSVariantIFC(Stack[Stack.Count-1],false);
|
psWriteln(makeString(NewTPSVariantIFC(Stack[Stack.Count-1],false)));
|
||||||
case arr.aType.BaseType of
|
end;
|
||||||
btString,btChar : psWriteln(stack.GetString(-1));
|
|
||||||
btU8, btS8, btU16, btS16, btU32, btS32: psWriteln(inttostr(stack.GetInt(-1)));
|
function ToStr_(Caller: TPSExec; p: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
|
||||||
{$IFNDEF PS_NOINT64}btS64 : psWriteln(IntToStr(stack.GetInt64(-1))); {$ENDIF}
|
var
|
||||||
else Result:=false;
|
data: TPSVariantIFC;
|
||||||
end;
|
begin
|
||||||
|
result := true;
|
||||||
|
Stack.SetAnsiString(-1, MakeString(NewTPSVariantIFC(Stack[Stack.Count-2],false)));
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function NewThreadCall(Procname : string) : Cardinal;
|
function NewThreadCall(Procname : string) : Cardinal;
|
||||||
@ -240,6 +253,7 @@ end;
|
|||||||
{$I PSInc/Wrappers/other.inc}
|
{$I PSInc/Wrappers/other.inc}
|
||||||
{$I PSInc/Wrappers/bitmap.inc}
|
{$I PSInc/Wrappers/bitmap.inc}
|
||||||
{$I PSInc/Wrappers/window.inc}
|
{$I PSInc/Wrappers/window.inc}
|
||||||
|
{$I PSInc/Wrappers/Strings.inc}
|
||||||
|
|
||||||
{$I PSInc/Wrappers/colour.inc}
|
{$I PSInc/Wrappers/colour.inc}
|
||||||
{$I PSInc/Wrappers/math.inc}
|
{$I PSInc/Wrappers/math.inc}
|
||||||
@ -412,6 +426,12 @@ begin
|
|||||||
OrgName:= 'x';
|
OrgName:= 'x';
|
||||||
Mode:= pmIn;
|
Mode:= pmIn;
|
||||||
end;
|
end;
|
||||||
|
with x.AddFunction('function ToStr:string').decl do
|
||||||
|
with addparam do
|
||||||
|
begin
|
||||||
|
OrgName:= 'x';
|
||||||
|
Mode:= pmIn;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMMLPSThread.OnExecImport(Sender: TObject; se: TPSExec;
|
procedure TMMLPSThread.OnExecImport(Sender: TObject; se: TPSExec;
|
||||||
@ -426,6 +446,7 @@ begin
|
|||||||
RIRegister_ExtCtrls(x);
|
RIRegister_ExtCtrls(x);
|
||||||
RIRegister_Mufasa(x);
|
RIRegister_Mufasa(x);
|
||||||
se.RegisterFunctionName('WRITELN',@Writeln_,nil,nil);
|
se.RegisterFunctionName('WRITELN',@Writeln_,nil,nil);
|
||||||
|
se.RegisterFunctionName('TOSTR',@ToStr_,nil,nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMMLPSThread.OutputMessages;
|
procedure TMMLPSThread.OutputMessages;
|
||||||
|
Loading…
Reference in New Issue
Block a user