From 1a393724472676b1440af168b4fcfa6d310a219c Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Wed, 31 May 2017 22:00:26 +0200 Subject: [PATCH] Fixed string conversion warning in lua_where Added LoadFromFile unit test --- Lua.API.pas | 2 +- UnitTests/source/TestWrapper.pas | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Lua.API.pas b/Lua.API.pas index a1a4133..6ef1730 100644 --- a/Lua.API.pas +++ b/Lua.API.pas @@ -742,7 +742,7 @@ begin lua_getinfo(L, 'Sl', ar); // get info about it if (ar.currentline > 0) then // is there info? begin - msg := Format('%s:%d: ', [ar.short_src, ar.currentline]); + msg := AnsiString(Format('%s:%d: ', [ar.short_src, ar.currentline])); lua_pushlstring(L, PAnsiChar(msg), Length(msg)); exit end; diff --git a/UnitTests/source/TestWrapper.pas b/UnitTests/source/TestWrapper.pas index 9829190..12b3417 100644 --- a/UnitTests/source/TestWrapper.pas +++ b/UnitTests/source/TestWrapper.pas @@ -54,12 +54,15 @@ type procedure RegisterObject; procedure RegisterObjectTable; + + procedure LoadFromFile; end; implementation uses - System.Classes; + System.Classes, + System.IOUtils; type @@ -500,6 +503,30 @@ begin end; +procedure TTestWrapper.LoadFromFile; +var + fileName: string; + script: TStringList; + +begin + fileName := TPath.GetTempFileName; + try + script := TStringList.Create; + try + script.Add('print("Hello world!")'); + script.SaveToFile(fileName); + finally + FreeAndNil(script); + end; + + Lua.LoadFromFile(fileName); + CheckEquals('Hello world!', Printed.ToString); + finally + TFile.Delete(fileName); + end; +end; + + { TTestObject } constructor TTestObject.Create(AOutput: TStringBuilder); begin