DWScript 2.1 preview 3 – now with type inference

A DWS 2.1 preview 3 7z archive is available at googlecode Delphi Web Script page, you can also get the same code via SVN of course.

This versions fixes several reported and unreported  issues, and adds support for type inference and Delphi Prism variable initialization syntax. Before you could write code like:

var myInteger : Integer = 1234;
var myObj : TSomeObject = TSomeObject.Create;

where ‘=‘ was used as assignment operator (using the same syntax as for constant declaration or default parameter values), you can now write the above using ‘:=‘ as well

var myInteger : Integer := 1234;
var myObj : TSomeObject := TSomeObject.Create;

and you additionally can make use of type inference and write just

var myInteger := 1234;
var myObj = TSomeObject.Create;

Type inference is currently limited to the variable declaration, this will probably stay for code clarity (opinions?). The inferred type isn’t restricted at the moment, but that will probably change (so you can disallow to inferring to a Variant type f.i.).

7 thoughts on “DWScript 2.1 preview 3 – now with type inference

  1. I haven’t seen in your example programs anywhere how to externally call a function defined with in the script.
    ie. MyScript.Execute(functionName,FunctionParameters,Result);
    Does DWScript have this ?

  2. Surprising as it may seem, I haven’t been using DWScript for strictly web purposes with the htmlfilter, so I don’t any sample website handy, so all there is right now are the htmlfilter unit tets. There may be one or two samples in the old DWS2 repository, if someone care to bring it/them up to speed.

  3. I tried to call the internal functions but kept getting
    a nil pointer for Prog.Info. until Debugging through your code I figured it out.
    The Prog.Info is nil if you call Prog.execute;
    The example should be :
    Var Prog : TdwsProgram;
    prog:=DelphiWebScript.Compile(memo1.lines.text);
    Prog.BeginProgram();
    sTemp := prog.Info.Func[‘test’].Call([i,j]).ValueAsString;
    Prog.EndProgram;

Comments are closed.