[go: up one dir, main page]

Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zaher committed Apr 9, 2022
1 parent 2b096e2 commit ba1f1b3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
13 changes: 12 additions & 1 deletion src/TyroLua.pas
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ TLuaScript = class(TTyroScript)
function DrawPoint_func(L: Plua_State): Integer; cdecl;
//global functions
function Print_func(L: Plua_State): Integer; cdecl;
function PrintLn_func(L: Plua_State): Integer; cdecl;

function Beep_func(L: Plua_State): Integer; cdecl;
function PlaySound_func(L: Plua_State): Integer; cdecl;
Expand Down Expand Up @@ -472,6 +473,7 @@ constructor TLuaScript.Create;
lua_register(LuaState, 'log', @log_func);
lua_register(LuaState, 'sleep', @sleep_func);
lua_register_method(LuaState, 'print', @Print_func);
lua_register_method(LuaState, 'println', @PrintLn_func);
lua_register_method(LuaState, 'window', @Window_func);
lua_register_method(LuaState, 'showconsole', @ShowConsole_func);

Expand Down Expand Up @@ -684,7 +686,16 @@ function TLuaScript.Print_func(L: Plua_State): Integer; cdecl;
s: string;
begin
s := lua_tostring(L, 1);
AddQueueObject(TPrintObject.Create(Main.Canvas, s));
AddQueueObject(TPrintObject.Create(Main.Canvas, s, False));
Result := 0;
end;

function TLuaScript.PrintLn_func(L: Plua_State): Integer; cdecl;
var
s: string;
begin
s := lua_tostring(L, 1);
AddQueueObject(TPrintObject.Create(Main.Canvas, s, True));
Result := 0;
end;

Expand Down
2 changes: 1 addition & 1 deletion src/TyroPascal.pas
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ function TPasScript.DrawPoint_func(x, y: integer): Integer;

function TPasScript.Print_func(s: string): Integer;
begin
AddQueueObject(TPrintObject.Create(Main.Canvas, s));
AddQueueObject(TPrintObject.Create(Main.Canvas, s, False));
Result := 0;
end;

Expand Down
11 changes: 8 additions & 3 deletions src/TyroScripts.pas
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ TDrawTextObject = class(TDrawObject)
TPrintObject = class(TDrawObject)
public
FText: String;
constructor Create(ACanvas: TTyroCanvas; Text: String);
FNewLine: Boolean;
constructor Create(ACanvas: TTyroCanvas; Text: String; NewLine: Boolean);
procedure DoExecute; override;
end;

Expand Down Expand Up @@ -526,15 +527,19 @@ procedure TDrawRectangleObject.DoExecute;

{ TPrintObject }

constructor TPrintObject.Create(ACanvas: TTyroCanvas; Text: String);
constructor TPrintObject.Create(ACanvas: TTyroCanvas; Text: String; NewLine: Boolean);
begin
inherited Create(ACanvas);
fText := Text;
fNewLine := NewLine;
end;

procedure TPrintObject.DoExecute;
begin
Main.Console.Writeln(fText);
if FNewLine then
Main.Console.Writeln(fText)
else
Main.Console.Write(fText);
end;

{ TDrawTextObject }
Expand Down
4 changes: 4 additions & 0 deletions src/tyro.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
<Filename Value="tyrolib\TyroClasses.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="TyroConsoles.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
19 changes: 13 additions & 6 deletions src/tyro.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils, Classes, CustApp, RayLib, RayClasses,
mnUtils, Melodies, TyroControls, TyroClasses,
TyroEditors, mnLogs, TyroSounds, TyroEngines,
TyroLua, TyroPascal, TyroScripts; //Add all languages units here
SysUtils, Classes, CustApp, RayLib, RayClasses, mnUtils, Melodies,
TyroControls, TyroClasses, TyroEditors, mnLogs, TyroSounds, TyroEngines,
TyroLua, TyroPascal, TyroScripts, TyroConsoles; //Add all languages units here

type

Expand Down Expand Up @@ -211,9 +210,17 @@ procedure TTyroApplication.DoRun;
begin
inherited;
try
Main.Run;
try
Main.Run;
except
on E:Exception do
begin
if IsConsole then
WriteLn(E.Message);
end;
end;
finally
Terminate;
except
end;
end;

Expand Down
2 changes: 1 addition & 1 deletion src/tyrolib/TyroControls.pas
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ function TTyroWindow.CreateCanvas: TTyroCanvas;
end;

initialization
finalization
Randomize;
finalization
FreeAndNil(Main);
end.

0 comments on commit ba1f1b3

Please sign in to comment.