mirror of
https://github.com/moparisthebest/Simba
synced 2025-01-30 14:50:18 -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;
|
||||
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;
|
||||
begin;
|
||||
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(nil,'procedure writeln(s : string);'); //We use special function for this
|
||||
AddFunction(nil,'procedure writeln(x);'); //We use special function for this
|
||||
|
||||
{ DTM }
|
||||
SetCurrSection('DTM');
|
||||
@ -96,8 +96,19 @@ AddFunction(@NewThreadCall,'function NewThreadCall(procname : string) : cardinal
|
||||
|
||||
|
||||
{string}
|
||||
SetCurrSection('String');
|
||||
AddFunction(@Capitalize,'function Capitalize(str : string) : 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}
|
||||
SetCurrSection('Web');
|
||||
|
@ -143,18 +143,31 @@ begin
|
||||
writeln(str);
|
||||
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;
|
||||
var
|
||||
arr: TPSVariantIFC;
|
||||
begin
|
||||
Result:=true;
|
||||
arr:=NewTPSVariantIFC(Stack[Stack.Count-1],false);
|
||||
case arr.aType.BaseType of
|
||||
btString,btChar : psWriteln(stack.GetString(-1));
|
||||
btU8, btS8, btU16, btS16, btU32, btS32: psWriteln(inttostr(stack.GetInt(-1)));
|
||||
{$IFNDEF PS_NOINT64}btS64 : psWriteln(IntToStr(stack.GetInt64(-1))); {$ENDIF}
|
||||
else Result:=false;
|
||||
end;
|
||||
psWriteln(makeString(NewTPSVariantIFC(Stack[Stack.Count-1],false)));
|
||||
end;
|
||||
|
||||
function ToStr_(Caller: TPSExec; p: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
|
||||
var
|
||||
data: TPSVariantIFC;
|
||||
begin
|
||||
result := true;
|
||||
Stack.SetAnsiString(-1, MakeString(NewTPSVariantIFC(Stack[Stack.Count-2],false)));
|
||||
|
||||
end;
|
||||
|
||||
function NewThreadCall(Procname : string) : Cardinal;
|
||||
@ -240,6 +253,7 @@ end;
|
||||
{$I PSInc/Wrappers/other.inc}
|
||||
{$I PSInc/Wrappers/bitmap.inc}
|
||||
{$I PSInc/Wrappers/window.inc}
|
||||
{$I PSInc/Wrappers/Strings.inc}
|
||||
|
||||
{$I PSInc/Wrappers/colour.inc}
|
||||
{$I PSInc/Wrappers/math.inc}
|
||||
@ -412,6 +426,12 @@ begin
|
||||
OrgName:= 'x';
|
||||
Mode:= pmIn;
|
||||
end;
|
||||
with x.AddFunction('function ToStr:string').decl do
|
||||
with addparam do
|
||||
begin
|
||||
OrgName:= 'x';
|
||||
Mode:= pmIn;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMMLPSThread.OnExecImport(Sender: TObject; se: TPSExec;
|
||||
@ -426,6 +446,7 @@ begin
|
||||
RIRegister_ExtCtrls(x);
|
||||
RIRegister_Mufasa(x);
|
||||
se.RegisterFunctionName('WRITELN',@Writeln_,nil,nil);
|
||||
se.RegisterFunctionName('TOSTR',@ToStr_,nil,nil);
|
||||
end;
|
||||
|
||||
procedure TMMLPSThread.OutputMessages;
|
||||
|
Loading…
Reference in New Issue
Block a user