Skip to content

Commit

Permalink
Magic method ImageFromString. Eventually needs to be replaced by addi…
Browse files Browse the repository at this point in the history
…ng const methods to lape.
  • Loading branch information
ollydev committed Feb 25, 2024
1 parent 1a7a135 commit ee9af67
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
<PackageName Value="LCL"/>
</Item5>
</RequiredPackages>
<Units Count="122">
<Units Count="123">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -956,6 +956,10 @@
<Filename Value="hash/simba.hash_crc64.pas"/>
<IsPartOfProject Value="True"/>
</Unit121>
<Unit122>
<Filename Value="script/simba.script_compiler_imagefromstring.pas"/>
<IsPartOfProject Value="True"/>
</Unit122>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
3 changes: 2 additions & 1 deletion Source/script/simba.script_compiler.pas
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ implementation

uses
lpeval,
simba.script_imports, simba.script_compiler_sleepuntil, simba.script_compiler_rtti;
simba.script_imports, simba.script_compiler_sleepuntil, simba.script_compiler_rtti, simba.script_compiler_imagefromstring;

function TSimbaScript_Compiler.addGlobalFunc(Header: lpString; Body: TStringArray): TLapeTree_Method;
var
Expand Down Expand Up @@ -130,6 +130,7 @@ procedure TSimbaScript_Compiler.Import;

ImportingSection := 'System';

InitializeImageFromString(Self);
InitializeSleepUntil(Self);
InitializeFFI(Self);
InitializeRTTI(Self);
Expand Down
68 changes: 68 additions & 0 deletions Source/script/simba.script_compiler_imagefromstring.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.script_compiler_imagefromstring;

{$i simba.inc}

interface

uses
classes, sysutils,
lpcompiler;

procedure InitializeImageFromString(Compiler: TLapeCompiler);

implementation

uses
lptypes, lptree, lpvartypes, lpmessages,
simba.image;

type
TLapeTree_InternalMethod_ImageFromString = class(TLapeTree_InternalMethod)
public
function resType: TLapeType; override;
function Evaluate: TLapeGlobalVar; override;
constructor Create(ACompiler: TLapeCompilerBase; ADocPos: PDocPos=nil); override;
end;

procedure InitializeImageFromString(Compiler: TLapeCompiler);
begin
Compiler.InternalMethodMap['ImageFromString'] := TLapeTree_InternalMethod_ImageFromString;
end;

function TLapeTree_InternalMethod_ImageFromString.resType: TLapeType;
begin
if (FResType = nil) then
FResType := FCompiler.getGlobalType('TImage');
Result := inherited;
end;

function TLapeTree_InternalMethod_ImageFromString.Evaluate: TLapeGlobalVar;
var
Param: TLapeGlobalVar;
begin
if (FParams.Count <> 1) then
LapeExceptionFmt(lpeWrongNumberParams, [1], DocPos);
Param := FParams[0].Evaluate;
if (Param.BaseType <> ltAnsiString) then
LapeExceptionFmt(lpeExpected, ['String parameter'], DocPos);

Result := resType().NewGlobalVarP();

PSimbaImage(Result.Ptr)^ := TSimbaImage.CreateFromString(PAnsiString(Param.Ptr)^);
PSimbaImage(Result.Ptr)^.FreeOnTerminate := True;
end;

constructor TLapeTree_InternalMethod_ImageFromString.Create(ACompiler: TLapeCompilerBase; ADocPos: PDocPos);
begin
inherited Create(ACompiler, ADocPos);

FConstant := bTrue;
end;

end.

2 changes: 1 addition & 1 deletion Third-Party/lape

0 comments on commit ee9af67

Please sign in to comment.