RTTI Exposure for DWScript

New in the SVN is a dwsRTTIExposer unit, whose purpose will be to expose Delphi classes and other types via RTTI to a script.

You’ll need Delphi 2010 or XE to use it, the functionality is implemented as a class helper for the TdwsUnit component.

Currently it supports isolated classes only, properties (non-array), methods and enumerations (contiguous). By default, only published members are exposed to the script, and you have two attributes to explicitly publish public members, or not publish published members. You can also specify a different script-side name for the member.

The following code sample (taken from a unit test) illustrates the various basic options:

TSimpleClass = class
   private
      FValue : Integer;

   public
      [dwsPublished]
      procedure DecValue;

   published
      [dwsPublished('CreateValued')]
      constructor Create(val : Integer);

      procedure IncValue;

      [dwsNotPublished]
      procedure NullValue; 

      property Value : Integer read FValue write FValue;
end;

There are some quirks, f.i. RTTI doesn’t expose array properties. YMMV, but about most classes I expose to script have at least one array property involved at some point… Some mechanism to specify them explicitly, or auto-detect them from getter-setters will be required.

There are quite a few more design issues to be taken care of at this point, among them exposing class hierarchies in script that could be different from the actual Delphi-side hierarchy, handling of “wrapped” Delphi instances (if a class has members that return dynamic instances, some two-way glue will be needed to manage the relationship), etc. The RTTI Invoke() mechanism is also not very efficient, so some work will be required in that area.

Finally, RTTI doesn’t expose enumerations with explicit, non-contiguous values, so they are currently unsupported by dwsRTTIExposer.

5 thoughts on “RTTI Exposure for DWScript

  1. Given your report, I’m disappointed the array property limitation in particular hasn’t been fixed in XE. Have you been able to press for this to be rectified…?

    That said, did you mean to give the Google Code link? As it is, you’ve linked to the original SourceForge site.

  2. Yes, meant the googlecode link, fixed, thanks 😉

    I haven’t “pressed” yet, as I hadn’t looked into the RTTI unit before that. So far the RTTI seems full of missing bits here and there, almost like it was designed from a C++ user POV, and lacks on what are IMHO key Delphi differentiating concepts.

  3. “So far the RTTI seems full of missing bits here and there”

    When playing around with the D2010 trial last year, I came up with a small list – see http://delphihaven.wordpress.com/2009/09/07/something-new-for-something-old-the-code/. One thing I didn’t list but might have was how it would be nice for enumerators to be explicitly surfaced in a high level fashion (i.e., have a TRttiEnumerator class) – what I did for my IDispatch implementation was to manually look for the pattern, but it only works if the pattern is implemented using a class, which it need not be of course.

Comments are closed.