mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-22 09:12:19 -05:00
Added PlaySound for Windows, fixed the way errordata is displayed (PascalScript mucks up at returning the right coordinates..)
Added Include_once, made it look for includes in more dirs (scriptpath, includepath and the current-file-path, fixed bug in Bitmaps where it would not set the bitmap to 'nil' in the actual BMP array. Fixed bug in ScriptPath (it would not include a trailing delimiter) git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@558 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
e6027ce05c
commit
4bd62c7237
@ -247,9 +247,7 @@ begin
|
|||||||
if ErrorData.Module <> '' then
|
if ErrorData.Module <> '' then
|
||||||
begin;
|
begin;
|
||||||
if not FileExists(ErrorData.Module) then
|
if not FileExists(ErrorData.Module) then
|
||||||
ErrorData.Module := ErrorData.IncludePath + ErrorData.Module;
|
Writeln(Format('ERROR comes from a non-existing file (%s)',[ErrorData.Module]))
|
||||||
if not FileExists(ErrorData.Module) then
|
|
||||||
Writeln('ERROR comes from a non-existing file....')
|
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
ErrorData.Module:= SetDirSeparators(ErrorData.Module);// Set it right ;-)
|
ErrorData.Module:= SetDirSeparators(ErrorData.Module);// Set it right ;-)
|
||||||
@ -270,13 +268,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
MakeActiveScriptFrame;
|
MakeActiveScriptFrame;
|
||||||
ScriptErrorLine:= ErrorData.Line;
|
ScriptErrorLine:= ErrorData.Row;
|
||||||
SynEdit.Invalidate;
|
SynEdit.Invalidate;
|
||||||
SynEdit.SelStart:= ErrorData.Position;
|
if ErrorData.Col = -1 then
|
||||||
if pos('error',lowercase(ErrorData.Error)) > 0 then
|
SynEdit.SelStart:= ErrorData.Position
|
||||||
formWriteln(Format('%s at line %d',[ErrorData.Error,ErrorData.Line]))
|
|
||||||
else
|
else
|
||||||
formWriteln(Format('Error: %s at line %d',[ErrorData.Error,ErrorData.Line]));
|
SynEdit.LogicalCaretXY := Point(ErrorData.Col,ErrorData.Row);
|
||||||
|
if pos('error',lowercase(ErrorData.Error)) > 0 then
|
||||||
|
formWriteln(Format('%s at line %d',[ErrorData.Error,ErrorData.Row]))
|
||||||
|
else
|
||||||
|
formWriteln(Format('Error: %s at line %d',[ErrorData.Error,ErrorData.Row]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TScriptFrame.MakeActiveScriptFrame;
|
procedure TScriptFrame.MakeActiveScriptFrame;
|
||||||
@ -342,6 +343,7 @@ begin
|
|||||||
MarkCaret.IgnoreKeywords := true;
|
MarkCaret.IgnoreKeywords := true;
|
||||||
end;
|
end;
|
||||||
AddKey(SynEdit,ecCodeCompletion,VK_SPACE,[ssCtrl]);
|
AddKey(SynEdit,ecCodeCompletion,VK_SPACE,[ssCtrl]);
|
||||||
|
// TSynPasSyn(SynEdit.Highlighter).NestedComments:= false; Does not work :(
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TScriptFrame.Destroy;
|
destructor TScriptFrame.Destroy;
|
||||||
|
@ -931,7 +931,7 @@ begin
|
|||||||
Thread.OnError:= @CurrScript.HandleErrorData;
|
Thread.OnError:= @CurrScript.HandleErrorData;
|
||||||
|
|
||||||
if CurrScript.ScriptFile <> '' then
|
if CurrScript.ScriptFile <> '' then
|
||||||
ScriptPath := ExtractFileDir(CurrScript.ScriptFile);
|
ScriptPath := IncludeTrailingPathDelimiter(ExtractFileDir(CurrScript.ScriptFile));
|
||||||
|
|
||||||
if DirectoryExists(PluginsPath) then
|
if DirectoryExists(PluginsPath) then
|
||||||
PluginsGlob.AddPath(PluginsPath);
|
PluginsGlob.AddPath(PluginsPath);
|
||||||
|
@ -42,6 +42,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
|
procedure PlaySound( Sound : string); extdecl;
|
||||||
|
begin
|
||||||
|
{$ifdef MSWINDOWS}
|
||||||
|
sndPlaySound(PChar(sound),SND_ASYNC or SND_NODEFAULT);
|
||||||
|
{$else}
|
||||||
|
Writeln(Format('Playing sound %s (not supported yet on Linux)',[sound]);
|
||||||
|
{$endif}
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure StopSound; extdecl;
|
||||||
|
begin;
|
||||||
|
{$ifdef MSWINDOWS}
|
||||||
|
sndPlaySoundW(nil,0);
|
||||||
|
{$else}
|
||||||
|
Writeln('Stopping sound is not supported yet on Linux');
|
||||||
|
{$endif}
|
||||||
|
end;
|
||||||
|
|
||||||
procedure ClearDebug; extdecl;
|
procedure ClearDebug; extdecl;
|
||||||
begin
|
begin
|
||||||
if Assigned(CurrThread.DebugMemo) then
|
if Assigned(CurrThread.DebugMemo) then
|
||||||
|
@ -126,6 +126,8 @@ AddFunction(@DrawBitmapDebugImg,'procedure DrawBitmapDebugImg(bmp: integer);');
|
|||||||
AddFunction(@GetDebugBitmap,'function GetDebugBitmap: integer;');
|
AddFunction(@GetDebugBitmap,'function GetDebugBitmap: integer;');
|
||||||
AddFunction(@ps_Random,'function Random(Int: integer): integer;');
|
AddFunction(@ps_Random,'function Random(Int: integer): integer;');
|
||||||
AddFunction(@ClearDebug,'procedure ClearDebug;');
|
AddFunction(@ClearDebug,'procedure ClearDebug;');
|
||||||
|
AddFunction(@PlaySound,'procedure PlaySound( Sound : string);');
|
||||||
|
AddFunction(@StopSound,'Procedure StopSound;');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ type
|
|||||||
TErrorType = (errRuntime,errCompile);
|
TErrorType = (errRuntime,errCompile);
|
||||||
TOnError = procedure of object;
|
TOnError = procedure of object;
|
||||||
TErrorData = record
|
TErrorData = record
|
||||||
Line,Position : integer;
|
Row,Col,Position : integer;
|
||||||
Error : string;
|
Error : string;
|
||||||
ErrType : TErrorType;
|
ErrType : TErrorType;
|
||||||
Module : string;
|
Module : string;
|
||||||
@ -78,6 +78,7 @@ type
|
|||||||
DebugTo: TWritelnProc;
|
DebugTo: TWritelnProc;
|
||||||
DebugImg : TDbgImgInfo;
|
DebugImg : TDbgImgInfo;
|
||||||
ExportedMethods : TExpMethodArr;
|
ExportedMethods : TExpMethodArr;
|
||||||
|
Includes : TStringList;
|
||||||
procedure LoadPlugin(plugidx: integer); virtual; abstract;
|
procedure LoadPlugin(plugidx: integer); virtual; abstract;
|
||||||
|
|
||||||
public
|
public
|
||||||
@ -91,9 +92,9 @@ type
|
|||||||
OnError : TOnError; //Error handeler
|
OnError : TOnError; //Error handeler
|
||||||
|
|
||||||
CompileOnly : boolean;
|
CompileOnly : boolean;
|
||||||
procedure HandleError(ErrorAtLine,ErrorPosition : integer; ErrorStr : string; ErrorType : TErrorType; ErrorModule : string);
|
procedure HandleError(ErrorRow,ErrorCol,ErrorPosition : integer; ErrorStr : string; ErrorType : TErrorType; ErrorModule : string);
|
||||||
function ProcessDirective(DirectiveName, DirectiveArgs: string): boolean;
|
function ProcessDirective(DirectiveName, DirectiveArgs: string): boolean;
|
||||||
function LoadFile(var filename, contents: string): boolean;
|
function LoadFile(ParentFile : string; var filename, contents: string): boolean;
|
||||||
procedure AddMethod(meth: TExpMethod); virtual;
|
procedure AddMethod(meth: TExpMethod); virtual;
|
||||||
|
|
||||||
procedure SetScript(Script : string);
|
procedure SetScript(Script : string);
|
||||||
@ -174,7 +175,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
colour_conv,dtmutil,
|
colour_conv,dtmutil,
|
||||||
{$ifdef mswindows}windows,{$endif}
|
{$ifdef mswindows}windows, MMSystem,{$endif}//MMSystem -> Sounds
|
||||||
uPSC_std, uPSC_controls,uPSC_classes,uPSC_graphics,uPSC_stdctrls,uPSC_forms,
|
uPSC_std, uPSC_controls,uPSC_classes,uPSC_graphics,uPSC_stdctrls,uPSC_forms,
|
||||||
uPSC_extctrls, //Compile-libs
|
uPSC_extctrls, //Compile-libs
|
||||||
uPSUtils,
|
uPSUtils,
|
||||||
@ -273,6 +274,8 @@ begin
|
|||||||
CompileOnly := false;
|
CompileOnly := false;
|
||||||
OnTerminate := @OnThreadTerminate;
|
OnTerminate := @OnThreadTerminate;
|
||||||
OnError:= nil;
|
OnError:= nil;
|
||||||
|
Includes := TStringList.Create;
|
||||||
|
Includes.CaseSensitive:= {$ifdef linux}true{$else}false{$endif};
|
||||||
inherited Create(CreateSuspended);
|
inherited Create(CreateSuspended);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -280,14 +283,16 @@ destructor TMThread.Destroy;
|
|||||||
begin
|
begin
|
||||||
MInternet.Free;
|
MInternet.Free;
|
||||||
Client.Free;
|
Client.Free;
|
||||||
|
Includes.free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMThread.HandleError(ErrorAtLine, ErrorPosition: integer; ErrorStr: string; ErrorType: TErrorType; ErrorModule : string);
|
procedure TMThread.HandleError(ErrorRow,ErrorCol, ErrorPosition: integer; ErrorStr: string; ErrorType: TErrorType; ErrorModule : string);
|
||||||
begin
|
begin
|
||||||
if OnError = nil then
|
if OnError = nil then
|
||||||
exit;
|
exit;
|
||||||
ErrorData^.Line:= ErrorAtLine;
|
ErrorData^.Row:= ErrorRow;
|
||||||
|
ErrorData^.Col := ErrorCol;
|
||||||
ErrorData^.Position:= ErrorPosition;
|
ErrorData^.Position:= ErrorPosition;
|
||||||
ErrorData^.Error:= ErrorStr;
|
ErrorData^.Error:= ErrorStr;
|
||||||
ErrorData^.ErrType:= ErrorType;
|
ErrorData^.ErrType:= ErrorType;
|
||||||
@ -305,10 +310,57 @@ procedure TMThread.AddMethod(meth: TExpMethod);
|
|||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function FindFile(filename : string; Dirs : array of string) : string; //Results '' if not found
|
||||||
|
var
|
||||||
|
i : integer;
|
||||||
|
begin;
|
||||||
|
if fileexists(filename) then
|
||||||
|
result := filename
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
for i := 0 to high(Dirs) do
|
||||||
|
if DirectoryExists(dirs[i]) then
|
||||||
|
if fileexists(dirs[i] + filename) then
|
||||||
|
begin
|
||||||
|
result := dirs[i] + filename;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMThread.LoadFile(ParentFile : string; var filename, contents: string): boolean;
|
||||||
|
var
|
||||||
|
path: string;
|
||||||
|
f: TFileStream;
|
||||||
|
begin
|
||||||
|
path := FindFile(filename,[includepath,ScriptPath,IncludeTrailingPathDelimiter(ExtractFileDir(parentfile))]);
|
||||||
|
if path = '' then
|
||||||
|
begin
|
||||||
|
psWriteln(Path + ' doesn''t exist');
|
||||||
|
Result := false;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
filename := path;//Yeah!
|
||||||
|
Includes.Add(path);
|
||||||
|
|
||||||
|
try
|
||||||
|
f:= TFileStream.Create(Path, fmOpenRead or fmShareDenyWrite);
|
||||||
|
SetLength(contents, f.Size);
|
||||||
|
f.Read(contents[1], Length(contents));
|
||||||
|
result:= true;
|
||||||
|
f.free;
|
||||||
|
except
|
||||||
|
Result := false;
|
||||||
|
psWriteln('ERROR in TMThread.LoadFile');
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TMThread.ProcessDirective(DirectiveName, DirectiveArgs: string): boolean;
|
function TMThread.ProcessDirective(DirectiveName, DirectiveArgs: string): boolean;
|
||||||
var
|
var
|
||||||
plugin_idx, i: integer;
|
plugin_idx, i: integer;
|
||||||
|
path : string;
|
||||||
begin
|
begin
|
||||||
|
result := false;
|
||||||
if CompareText(DirectiveName,'LOADDLL') = 0 then
|
if CompareText(DirectiveName,'LOADDLL') = 0 then
|
||||||
begin
|
begin
|
||||||
if DirectiveArgs <> '' then
|
if DirectiveArgs <> '' then
|
||||||
@ -316,45 +368,28 @@ begin
|
|||||||
plugin_idx:= PluginsGlob.LoadPlugin(DirectiveArgs);
|
plugin_idx:= PluginsGlob.LoadPlugin(DirectiveArgs);
|
||||||
if plugin_idx < 0 then
|
if plugin_idx < 0 then
|
||||||
psWriteln(Format('Your DLL %s has not been found',[DirectiveArgs]))
|
psWriteln(Format('Your DLL %s has not been found',[DirectiveArgs]))
|
||||||
else
|
else begin
|
||||||
LoadPlugin(plugin_idx);
|
LoadPlugin(plugin_idx);
|
||||||
end;
|
|
||||||
end;
|
|
||||||
result:= True;
|
result:= True;
|
||||||
end;
|
end;
|
||||||
|
end else
|
||||||
function TMThread.LoadFile(var filename, contents: string): boolean;
|
psWriteln('Your LoadDLL directive has no params, thus cannot find the plugin');
|
||||||
var
|
end else
|
||||||
path: string;
|
if CompareText(DirectiveName,'INCLUDE_ONCE') = 0 then
|
||||||
f: TFileStream;
|
|
||||||
begin
|
|
||||||
if FileExists(filename) then
|
|
||||||
path:= filename
|
|
||||||
else
|
|
||||||
path:= IncludePath + filename;
|
|
||||||
if not FileExists(path) then
|
|
||||||
begin
|
begin
|
||||||
psWriteln(Path + ' doesn''t exist');
|
result := true; //Lets to the actual file checking later on in the preprocessor ;-)
|
||||||
Result := false;
|
if DirectiveArgs <> '' then
|
||||||
Exit;
|
begin
|
||||||
|
path := FindFile(DirectiveArgs,[ScriptPath,IncludePath]);
|
||||||
|
if path <> '' then
|
||||||
|
if Includes.Find(path,i) then
|
||||||
|
begin
|
||||||
|
psWriteln('Include_Once file already included');
|
||||||
|
result := false;
|
||||||
end;
|
end;
|
||||||
try
|
|
||||||
f:= TFileStream.Create(Path, fmOpenRead or fmShareDenyWrite);
|
|
||||||
except
|
|
||||||
Result := false;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
try
|
|
||||||
try
|
|
||||||
SetLength(contents, f.Size);
|
|
||||||
f.Read(contents[1], Length(contents));
|
|
||||||
result:= true;
|
|
||||||
finally
|
|
||||||
f.free;
|
|
||||||
end;
|
|
||||||
except
|
|
||||||
result:= false;
|
|
||||||
end;
|
end;
|
||||||
|
end else
|
||||||
|
result := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMThread.SetDebug(writelnProc: TWritelnProc);
|
procedure TMThread.SetDebug(writelnProc: TWritelnProc);
|
||||||
@ -376,8 +411,9 @@ begin
|
|||||||
FontPath:= FontP;
|
FontPath:= FontP;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant; stdcall;
|
function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant; extdecl;
|
||||||
begin
|
begin
|
||||||
|
Writeln('yo');
|
||||||
CurrThread.SyncInfo^.MethodName:= ProcName;
|
CurrThread.SyncInfo^.MethodName:= ProcName;
|
||||||
CurrThread.SyncInfo^.V:= V;
|
CurrThread.SyncInfo^.V:= V;
|
||||||
CurrThread.SyncInfo^.OldThread := CurrThread;
|
CurrThread.SyncInfo^.OldThread := CurrThread;
|
||||||
@ -550,7 +586,7 @@ end;
|
|||||||
function TPSThread.RequireFile(Sender: TObject;
|
function TPSThread.RequireFile(Sender: TObject;
|
||||||
const OriginFileName: String; var FileName, OutPut: string): Boolean;
|
const OriginFileName: String; var FileName, OutPut: string): Boolean;
|
||||||
begin
|
begin
|
||||||
result:= LoadFile(FileName,OutPut);
|
result:= LoadFile(OriginFileName,FileName,OutPut);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SIRegister_Mufasa(cl: TPSPascalCompiler);
|
procedure SIRegister_Mufasa(cl: TPSPascalCompiler);
|
||||||
@ -659,7 +695,7 @@ begin
|
|||||||
b := True;
|
b := True;
|
||||||
if OnError <> nil then
|
if OnError <> nil then
|
||||||
with PSScript.CompilerMessages[l] do
|
with PSScript.CompilerMessages[l] do
|
||||||
HandleError(Row, Pos, MessageToString,errCompile, ModuleName)
|
HandleError(Row, Col, Pos, MessageToString,errCompile, ModuleName)
|
||||||
else
|
else
|
||||||
psWriteln(PSScript.CompilerErrorToStr(l) + ' at line ' + inttostr(PSScript.CompilerMessages[l].Row));
|
psWriteln(PSScript.CompilerErrorToStr(l) + ' at line ' + inttostr(PSScript.CompilerMessages[l].Row));
|
||||||
end else
|
end else
|
||||||
@ -682,7 +718,7 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
// if not (ScriptState = SCompiling) then
|
// if not (ScriptState = SCompiling) then
|
||||||
if not PSScript.Execute then
|
if not PSScript.Execute then
|
||||||
HandleError(PSScript.ExecErrorRow,PSScript.ExecErrorPosition,PSScript.ExecErrorToString,
|
HandleError(PSScript.ExecErrorRow,PSScript.ExecErrorCol,PSScript.ExecErrorPosition,PSScript.ExecErrorToString,
|
||||||
errRuntime, PSScript.ExecErrorFileName)
|
errRuntime, PSScript.ExecErrorFileName)
|
||||||
else
|
else
|
||||||
psWriteln('Succesfully executed');
|
psWriteln('Succesfully executed');
|
||||||
@ -733,9 +769,9 @@ end;
|
|||||||
procedure Interpreter_ErrorHandler(line, pos: integer; err: PChar; runtime: boolean); stdcall;
|
procedure Interpreter_ErrorHandler(line, pos: integer; err: PChar; runtime: boolean); stdcall;
|
||||||
begin
|
begin
|
||||||
if runtime then
|
if runtime then
|
||||||
CurrThread.HandleError(line,pos,err,errRuntime,'')
|
CurrThread.HandleError(line,-1,pos,err,errRuntime,'')
|
||||||
else
|
else
|
||||||
CurrThread.HandleError(line,pos,err,errCompile,'')
|
CurrThread.HandleError(line,-1,pos,err,errCompile,'')
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TCPThread.Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
constructor TCPThread.Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
||||||
|
@ -395,7 +395,8 @@ begin
|
|||||||
Writeln(Format('BMP[%d] has been freed.',[number]))
|
Writeln(Format('BMP[%d] has been freed.',[number]))
|
||||||
else
|
else
|
||||||
Writeln(Format('BMP[%s] has been freed.',[ToDestroy.BmpName]));
|
Writeln(Format('BMP[%s] has been freed.',[ToDestroy.BmpName]));
|
||||||
FreeAndNil(ToDestroy);
|
ToDestroy.Free;
|
||||||
|
BmpArray[number] := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMufasaBitmap.SaveToFile(const FileName: string): boolean;
|
function TMufasaBitmap.SaveToFile(const FileName: string): boolean;
|
||||||
|
@ -611,11 +611,10 @@ begin
|
|||||||
//-- 20050707_jgv - ask the application
|
//-- 20050707_jgv - ask the application
|
||||||
AppContinue := True;
|
AppContinue := True;
|
||||||
If @OnProcessDirective <> Nil then OnProcessDirective (Self, Parser, FDefineState.DoWrite, name, s, AppContinue);
|
If @OnProcessDirective <> Nil then OnProcessDirective (Self, Parser, FDefineState.DoWrite, name, s, AppContinue);
|
||||||
|
|
||||||
If AppContinue then
|
If AppContinue then
|
||||||
//-- end jgv
|
//-- end jgv
|
||||||
|
|
||||||
if (Name = 'I') or (Name = 'INCLUDE') or (Name = '.INCLUDE') then
|
if (Name = 'I') or (Name = 'INCLUDE') or (Name = 'INCLUDE_ONCE') then
|
||||||
begin
|
begin
|
||||||
if FDefineState.DoWrite then
|
if FDefineState.DoWrite then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user