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.