Skip to content

Commit

Permalink
Finish new file interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jul 10, 2023
1 parent 9e65e6b commit 33ef3fd
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 99 deletions.
64 changes: 25 additions & 39 deletions Source/script/imports/simba/simba.import_file.pas
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,24 @@ procedure _LapeDeleteINI(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
DeleteINI(PString(Params^[0])^, PString(Params^[1])^, PString(Params^[1])^);
end;

procedure _LapeUnZipFile(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
procedure _LapeZipExtractAll(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
UnZipFile(PString(Params^[0])^, PString(Params^[1])^);
PBoolean(Result)^ := ZipExtractAll(PString(Params^[0])^, PString(Params^[1])^);
end;

procedure _LapeUnZipOneFile(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
procedure _LapeZipExtractOne(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := UnZipOneFile(PString(Params^[0])^, PString(Params^[1])^, PString(Params^[2])^);
PBoolean(Result)^ := ZipExtractOne(PString(Params^[0])^, PString(Params^[1])^, PString(Params^[2])^);
end;

procedure _LapeZipFiles(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
procedure _LapeZipFiles(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
ZipFiles(PString(Params^[0])^, PStringArray(Params^[1])^);
PBoolean(Result)^ := ZipFiles(PString(Params^[0])^, PStringArray(Params^[1])^);
end;

procedure _LapeZipEntries(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PStringArray(Result)^ := ZipEntries(PString(Params^[0])^);
end;

procedure _LapeFileAppend(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
Expand Down Expand Up @@ -213,6 +218,11 @@ procedure _LapePathIncludeLeadingSep(const Params: PParamArray; const Result: Po
PString(Result)^ := TSimbaPath.PathIncludeLeadingSep(PString(Params^[0])^);
end;

procedure _LapePathExtractRelative(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PString(Result)^ := TSimbaPath.PathExtractRelative(PString(Params^[0])^, PString(Params^[1])^);
end;

procedure _LapeDirList(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PStringArray(Result)^ := TSimbaDir.DirList(PString(Params^[0])^, PBoolean(Params^[1])^);
Expand Down Expand Up @@ -273,39 +283,15 @@ procedure _LapeGetTempFileName(const Params: PParamArray; const Result: Pointer)
PString(Result)^ := GetTempFileName();
end;

procedure _LapeGetEnvVar(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PString(Result)^ := GetEnvironmentVariable(PString(Params^[0])^);
end;

procedure _LapeGetEnvVars(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV

function _GetEnvVars: TStringArray;
var
Count, I: Integer;
begin
Count := 0;

SetLength(Result, GetEnvironmentVariableCount() + 1);
for I := 1 to GetEnvironmentVariableCount() do
if (GetEnvironmentString(I) <> '') then
begin
Result[Count] := GetEnvironmentString(I);
Inc(Count);
end;
SetLength(Result, Count);
end;

begin
PStringArray(Result)^ := _GetEnvVars();
end;

procedure ImportFile(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
begin
ImportingSection := 'File';

addGlobalVar(PATH_SEP, 'PATH_SEP').isConstant := True;
addGlobalVar(LINE_SEP, 'LINE_SEP').isConstant := True;

addGlobalVar(GetIncludePath(), 'IncludePath').isConstant := True;
addGlobalVar(GetPluginPath(), 'PluginPath').isConstant := True;
addGlobalVar(GetSimbaPath(), 'SimbaPath').isConstant := True;
Expand All @@ -316,17 +302,16 @@ procedure ImportFile(Compiler: TSimbaScript_Compiler);
addGlobalFunc('procedure WriteINI(Section, KeyName, NewString, FileName: String)', @_LapeWriteINI);
addGlobalFunc('function ReadINI(Section, KeyName, FileName: String): String', @_LapeReadINI);
addGlobalFunc('procedure DeleteINI(Section, KeyName, FileName: String)', @_LapeDeleteINI);
addGlobalFunc('procedure ZipFiles(ArchiveFileName: String; const Files: TStringArray)', @_LapeZipFiles);
addGlobalFunc('procedure UnZipFile(ArchiveFileName, OutputDirectory: String)', @_LapeUnZipFile);
addGlobalFunc('function UnZipOneFile(ArchiveFileName, FileName, OutputDirectory: String): Boolean', @_LapeUnZipOneFile);

addGlobalFunc('function ZipExtractAll(ZipFileName, OutputDir: String): Boolean', @_LapeZipExtractAll);
addGlobalFunc('function ZipExtractOne(ZipFileName, FileName, OutputDir: String): Boolean', @_LapeZipExtractOne);
addGlobalFunc('function ZipFiles(ZipFileName: String; Files: TStringArray): Boolean', @_LapeZipFiles);
addGlobalFunc('function ZipEntries(ZipFileName: String): TStringArray', @_LapeZipEntries);

addGlobalFunc('function GetUserDir: String', @_LapeGetUserDir);
addGlobalFunc('function GetTempDir: String', @_LapeGetTempDir);
addGlobalFunc('function GetTempFileName: String', @_LapeGetTempFileName);

addGlobalFunc('function GetEnvVar(Name: String): String', @_LapeGetEnvVar);
addGlobalFunc('function GetEnvVars: TStringArray', @_LapeGetEnvVars);

addGlobalFunc('function FileRead(FileName: String): String', @_LapeFileRead);
addGlobalFunc('function FileReadEx(FileName: String; Offset: Integer): String', @_LapeFileReadEx);
addGlobalFunc('function FileWrite(FileName: String; Text: String): Boolean', @_LapeFileWrite);
Expand Down Expand Up @@ -363,6 +348,7 @@ procedure ImportFile(Compiler: TSimbaScript_Compiler);
addGlobalFunc('function PathIncludeTrailingSep(Path: String): String', @_LapePathIncludeTrailingSep);
addGlobalFunc('function PathExcludeLeadingSep(Path: String): String', @_LapePathExcludeLeadingSep);
addGlobalFunc('function PathIncludeLeadingSep(Path: String): String', @_LapePathIncludeLeadingSep);
addGlobalFunc('function PathExtractRelative(BasePath, DestPath: String): String', @_LapePathExtractRelative);

addGlobalFunc('function DirList(Path: String; Recursive: Boolean = False): TStringArray', @_LapeDirList);
addGlobalFunc('function DirSearch(Path: String; Mask: String; Recursive: Boolean = False): TStringArray', @_LapeDirSearch);
Expand Down
43 changes: 31 additions & 12 deletions Source/script/imports/simba/simba.import_system.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ implementation
lptypes, lpparser, ffi,
simba.script_compiler, simba.mufasatypes, simba.nativeinterface;

procedure _LapeGetEnvironmentVariable(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PString(Result)^ := GetEnvironmentVariable(PString(Params^[0])^);
end;

procedure _LapeGetCurrentThreadID(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPtrUInt(Result)^ := PtrUInt(GetCurrentThreadID());
Expand All @@ -26,11 +21,6 @@ procedure _LapeGetMainThreadID(const Params: PParamArray; const Result: Pointer)
PPtrUInt(Result)^ := PtrUInt(MainThreadID);
end;

procedure _LapeWait(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
Sleep(PUInt32(Params^[0])^);
end;

procedure _LapePreciseSleep(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
SimbaNativeInterface.PreciseSleep(PUInt32(Params^[0])^);
Expand Down Expand Up @@ -65,6 +55,33 @@ procedure _LapeGetThreadCount(const Params: PParamArray; const Result: Pointer);
PPtrUInt(Result)^ := TThread.ProcessorCount;
end;

procedure _LapeGetEnvVar(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PString(Result)^ := GetEnvironmentVariable(PString(Params^[0])^);
end;

procedure _LapeGetEnvVars(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV

function _GetEnvVars: TStringArray;
var
Count, I: Integer;
begin
Count := 0;

SetLength(Result, GetEnvironmentVariableCount() + 1);
for I := 1 to GetEnvironmentVariableCount() do
if (GetEnvironmentString(I) <> '') then
begin
Result[Count] := GetEnvironmentString(I);
Inc(Count);
end;
SetLength(Result, Count);
end;

begin
PStringArray(Result)^ := _GetEnvVars();
end;

procedure ImportSystem(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
Expand Down Expand Up @@ -99,9 +116,9 @@ procedure ImportSystem(Compiler: TSimbaScript_Compiler);
addGlobalType('array of TColor', 'TColorArray');

addGlobalType('array of String', 'TStringArray');
addGlobalType('array of TStringArray', 'T2DStringArray');
addGlobalType('array of Integer', 'TIntegerArray');
addGlobalType('array of TIntegerArray', 'T2DIntegerArray');
addGlobalType('array of T2DIntegerArray', 'T3DIntegerArray');
addGlobalType('array of Int64', 'TInt64Array');
addGlobalType('array of Byte', 'TByteArray');
addGlobalType('array of Single', 'TSingleArray');
Expand All @@ -127,7 +144,6 @@ procedure ImportSystem(Compiler: TSimbaScript_Compiler);
addGlobalFunc('function GetThreadCount: Integer', @_LapeGetThreadCount);
addGlobalFunc('function GetMainThreadID: PtrUInt', @_LapeGetMainThreadID);
addGlobalFunc('function GetCurrentThreadID: PtrUInt', @_LapeGetCurrentThreadID);
addGlobalFunc('function GetEnvironmentVariable(const Name: String): String', @_LapeGetEnvironmentVariable);

addGlobalType('procedure() of object', 'TSyncMethod', {$IF DEFINED(CPU32) and DEFINED(LAPE_CDECL)}FFI_CDECL{$ELSE}FFI_DEFAULT_ABI{$ENDIF});
addGlobalFunc('procedure Sync(Method: TSyncMethod)', @_LapeSync);
Expand All @@ -139,6 +155,9 @@ procedure ImportSystem(Compiler: TSimbaScript_Compiler);
'end;'
]);

addGlobalFunc('function GetEnvVar(Name: String): String', @_LapeGetEnvVar);
addGlobalFunc('function GetEnvVars: TStringArray', @_LapeGetEnvVars);

ImportingSection := '';
end;
end;
Expand Down

0 comments on commit 33ef3fd

Please sign in to comment.