Fix in Scripting

This commit is contained in:
Michael Schimmel
2025-09-23 12:51:55 +02:00
parent 2f2c93d56e
commit 46d40cfbca
3 changed files with 24 additions and 11 deletions
+21 -1
View File
@@ -9,7 +9,8 @@ uses
Myc.Data.Series;
type
TDataValueKind = (vkVoid, vkScalar, vkText, vkSeries, vkRecordSeries, vkRecord, vkManagedObject, vkMethod, vkInterface, vkGeneric);
TDataValueKind =
(vkVoid, vkScalar, vkText, vkSeries, vkRecordSeries, vkRecord, vkManagedObject, vkMethod, vkInterface, vkPointer, vkGeneric);
TDataValue = record
type
@@ -64,6 +65,9 @@ type
class function FromGeneric<T>(const [ref] AValue: T): TDataValue; static; inline;
function AsGeneric<T>: T; inline;
class function FromPtr(const AValue: Pointer): TDataValue; static; inline;
function AsPtr: Pointer; inline;
class function Defer(const Value: TDataValue; const Calc: TFunc): TDataValue; overload; static;
class function Map(const SourceSeries: ISeries; const MapperFunc: TFunc): ISeries; static;
@@ -243,6 +247,15 @@ begin
Result := (FInterface as TObjVal).Value;
end;
function TDataValue.AsPtr: Pointer;
begin
if FKind = Ord(vkLazy) then
exit(AsLazy.Value.AsPtr);
if (FKind <> Ord(vkPointer)) then
raise EInvalidCast.Create('Cannot read value as pointer.');
Result := Pointer(FScalar.Value.AsInt64);
end;
function TDataValue.AsRecord: TScalarRecord;
begin
if FKind = Ord(vkLazy) then
@@ -320,6 +333,13 @@ begin
Result.FInterface := TVal<T>.Create(AValue);
end;
class function TDataValue.FromPtr(const AValue: Pointer): TDataValue;
begin
Assert(sizeof(Pointer) <= sizeof(Int64));
Result.FKind := Ord(vkPointer);
Result.FScalar.FromInt64(Int64(AValue));
end;
class function TDataValue.FromSeries(const AValue: ISeries): TDataValue;
begin
Result.FKind := Ord(vkSeries);