- DelphiTools - https://www.delphitools.info -

Everything’s got to end some day…

…and DWScript will likely enter RC phase before the year ends, as almost all of what I had in mind for 2.1 will be there!

Recent SVN [1] additions since the last update:

Class operators in DWScript

The first class operators are now implemented in DWScript, though the syntax differs from Delphi, FreePascal & Prism in that they are not special methods/procedures, but syntax-sugar aliases, in a fashion similar to what properties achieve.

class operator <operator> <rightType> uses <method>

To illustrate this with TList f.i., you could declare have

class operator += TObject uses Add;
class operator -= TObject uses Remove;

and so “myList += item” would be equivalent to “myList.Add(item)”.

Note that class operators support type overloading, it is thus possible to declare

TMyClass = class
   procedure AddInteger(i : Integer);
   procedure AddString(s : String);

   class operator += Integer uses AddInteger;
   class operator += String uses AddString;
end;

The method will be selected depending on the right operand type

myObject += 10; // will use AddInteger
myObject += 'ten'; // will use AddString;

Only compound-operators can be overloaded, overloading of other operators is not planned for 2.1.

For 2.2 and beyond, the plan is currently to not allow overloading of non-compound-operators in the scripts (at least not without a switch to control that ability), this is to keep ambiguous uses of operator overloading out of the scripts.

Delphi-side overloading definition will however be supported for class and add-on base types, one of the first uses will likely be for upcoming (optional) vector, matrix & other algebra types.