Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
1.1.0:scripting [2023/08/02 15:36] – [TypeCasts] admin1.1.0:scripting [2023/08/03 11:29] (current) – [Exit] admin
Line 136: Line 136:
 |shr|bitwise|operation to shift by a specific number of bits to the right| |shr|bitwise|operation to shift by a specific number of bits to the right|
 |shl|bitwise|operation to shift by a specific number of bits to the left| |shl|bitwise|operation to shift by a specific number of bits to the left|
 +|as|typecast|as operator for explicit type-casts, supported for classes or basic types (string, int, int64, boolean and floats)|
 +|in|check|checks if right side contains the left side. it's a multitype operator for enums or strings|
  
 ==== Routines ==== ==== Routines ====
Line 249: Line 251:
   LArr1[4] := LArr1[0];   LArr1[4] := LArr1[0];
   System.WriteLn(LArr1.ToString() + #13#10);   System.WriteLn(LArr1.ToString() + #13#10);
 +end;
 +  </file>
 +  * TypeCast Operator "as" for output conversion
 +  <file pascal>
 +var LStr : String;
 +    LFlt : Single;
 +begin
 +  // auto-string/bool/int/float conversion, will output here: "True"
 +  LStr := (('123' as Int32) as Boolean) as String;
 +  System.WriteLn(LStr as String);
 +  
 +  // auto-rounding, will output "124"
 +  LFlt := ((123.56789 as Int32) as Double);
 +  System.WriteLn(LFlt as String);
 end; end;
   </file>   </file>
Line 509: Line 525:
 end; end;
 </file> </file>
 +===== Syntax Elements =====
 +
 +Since Rev. 2730+ you're able to call EXIT or HALT like in Delphi syntax.
 +
 +==== Exit ====
 +
 +The exit statement will immediatly leave a function or program code.
 +
 +__NOTICE__: Currently it's not possible to directly set the result value in brackets!
 +
 +In the example below the function will return "A large value!" if the supplied argument is larger than 100.
 +Otherwise it will return the integer value as string.
 +
 +<file pascal>
 +function MyTest(AValue : Integer) : String;
 +begin
 +  if (AValue > 100) then
 +  begin
 +    Result := 'A large value!';
 +    Exit;
 +  end;
 +  
 +  Result := IntToStr(AValue);
 +end;
 +</file>
 +
 +==== Halt ====
 +
 +The HALT statement is useful to immediatly stop the program from execution.
 +It doesn't matter if you're in a function or in main program code. The executor will immediatly stop bytecode execution.
 +
 +In the example below we stop the program if the supplied argument is larger than 100.
 +Otherwise nothing will happen.
 +
 +<file pascal>
 +procedure StopMyProgram(AValue : Integer);
 +begin
 +  if (AValue > 100) then
 +    Halt;
 +end;
 +</file>
 +
 +
 ===== Classes ===== ===== Classes =====