diff --git a/.gitignore b/.gitignore index ac68bba..8c48922 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -__history \ No newline at end of file +__history +*.local +*.identcache +bin +lib \ No newline at end of file diff --git a/InteractiveTests/DelphiLuaInteractiveTests.dpr b/InteractiveTests/DelphiLuaInteractiveTests.dpr new file mode 100644 index 0000000..9750faf --- /dev/null +++ b/InteractiveTests/DelphiLuaInteractiveTests.dpr @@ -0,0 +1,19 @@ +program DelphiLuaInteractiveTests; + +uses + Vcl.Forms, + MainFrm in 'MainFrm.pas' {MainForm}, + Lua.API in '..\Lua.API.pas', + Lua in '..\Lua.pas'; + +{$R *.res} + +var + MainForm: TMainForm; + +begin + Application.Initialize; + Application.MainFormOnTaskbar := True; + Application.CreateForm(TMainForm, MainForm); + Application.Run; +end. diff --git a/InteractiveTests/DelphiLuaInteractiveTests.dproj b/InteractiveTests/DelphiLuaInteractiveTests.dproj new file mode 100644 index 0000000..a4ad1ce --- /dev/null +++ b/InteractiveTests/DelphiLuaInteractiveTests.dproj @@ -0,0 +1,163 @@ + + + {8EF9E49D-83BD-4B5D-B407-7CB3763E3730} + 13.4 + VCL + DelphiLuaInteractiveTests.dpr + True + Debug + Win32 + 1 + Application + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + None + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + 1043 + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + $(BDS)\bin\delphi_PROJECTICON.ico + DBXInterBaseDriver;DataSnapServer;DataSnapCommon;DbxCommonDriver;dbxcds;CustomIPTransport;dsnap;IndyCore;FmxTeeUI;IPIndyImpl;bindcompfmx;dbrtl;bindcomp;inetdb;xmlrtl;ibxpress;soaprtl;FMXTee;bindengine;DBXInformixDriver;DBXFirebirdDriver;inet;DBXSybaseASADriver;dbexpress;fmx;IndySystem;DataSnapClient;DataSnapProviderClient;DBXOracleDriver;inetdbxpress;rtl;DbxClientDriver;IndyProtocols;DBXMySQLDriver;DataSnapIndy10ServerTransport;$(DCC_UsePackage) + .\$(Platform)\$(Config) + .\$(Platform)\$(Config) + + + dxTileControlRS16;cxLibraryRS16;dxPsPrVwAdvRS16;dxRibbonCustomizationFormRS16;dxPSCoreRS16;dxRichEditInplaceRS16;dxPScxTLLnkRS16;dxPSdxSpreadSheetLnkRS16;cxPageControlRS16;dxPScxGridLnkRS16;vclimg;dxComnRS16;vcldb;dxOfficeCoreRS16;dxBarExtDBItemsRS16;dxSpreadSheetInplaceRichEditRS16;dxSpreadSheetCoreRS16;cxDataRS16;dxDockingRS16;dxPSDBTeeChartRS16;dxSpreadSheetReportDesignerRS16;dxBarExtItemsRS16;dxPSLnksRS16;dxPSdxPDFViewerLnkRS16;dxPSTeeChartRS16;dxPSdxLCLnkRS16;cxVerticalGridRS16;dxorgcRS16;dxWizardControlRS16;dxPScxExtCommonRS16;dxNavBarRS16;dxSpreadSheetCoreDialogsRS16;dxSpreadSheetCoreConditionalFormattingDialogsRS16;cxSchedulerTreeBrowserRS16;DBXOdbcDriver;dxdbtrRS16;dxRichEditCoreRS16;dxPSdxDBTVLnkRS16;vclactnband;dxPScxSchedulerLnkRS16;dxServerModeRS16;bindcompvcl;vclie;dsnapcon;dxHttpIndyRequestRS16;vclx;dxFlowChartRS16;dxGDIPlusRS16;dxdborRS16;dxPDFViewerRS16;dxEMFRS16;dxLayoutControlRS16;dxSpreadSheetRS16;dxPScxPivotGridLnkRS16;dxCoreRS16;dxPScxVGridLnkRS16;cxExportRS16;dxPSdxMapControlLnkRS16;dxBarRS16;TeeDB;dxDBXServerModeRS16;cxTreeListdxBarPopupMenuRS16;dxPSdxGaugeControlLnkRS16;dxRibbonRS16;DBXSybaseASEDriver;dxSpreadSheetConditionalFormattingDialogsRS16;cxTreeListRS16;vcldsnap;dxGaugeControlRS16;DBXDb2Driver;vcl;DBXMSSQLDriver;cxSchedulerGridRS16;dxRichEditControlCoreRS16;webdsnap;dxtrmdRS16;adortl;dxRichEditControlRS16;dxRichEditDocumentModelRS16;dxPSdxDBOCLnkRS16;Tee;cxPivotGridChartRS16;dxmdsRS16;dxSpellCheckerRS16;dxMapControlRS16;cxGridRS16;dxPScxCommonRS16;dxPSPrVwRibbonRS16;cxEditorsRS16;TeeUI;cxPivotGridRS16;cxSchedulerRibbonStyleEventEditorRS16;cxSchedulerRS16;vcltouch;websnap;dxFlowChartAdvancedCustomizeFormRS16;VclSmp;dxTabbedMDIRS16;dxPSRichEditControlLnkRS16;dxPSdxOCLnkRS16;dxPSdxFCLnkRS16;dxThemeRS16;dxPScxPCProdRS16;dxBarDBNavRS16;$(DCC_UsePackage) + + + dxTileControlRS16;JvGlobus;JvMM;cxLibraryRS16;JvManagedThreads;JvCrypt;rbDIDE1516;dxPsPrVwAdvRS16;dxRibbonCustomizationFormRS16;rbTCUI1516;dxPSCoreRS16;dxRichEditInplaceRS16;dxPScxTLLnkRS16;dxPSdxSpreadSheetLnkRS16;JvNet;cxPageControlRS16;dxPScxGridLnkRS16;JvDotNetCtrls;vclimg;rbDAD1516;dxComnRS16;JvXPCtrls;rbRCL1516;vcldb;dxOfficeCoreRS16;dxBarExtDBItemsRS16;rbIBE1516;dxSpreadSheetInplaceRichEditRS16;dclRBIBE1516;dclRBADO1516;dxSpreadSheetCoreRS16;CloudService;rbRAP1516;cxDataRS16;dxDockingRS16;dxPSDBTeeChartRS16;JvDB;JvRuntimeDesign;dxSpreadSheetReportDesignerRS16;X2CLMB;dxBarExtItemsRS16;dxPSLnksRS16;dxPSdxPDFViewerLnkRS16;JclDeveloperTools;dxPSTeeChartRS16;dxPSdxLCLnkRS16;cxVerticalGridRS16;dxorgcRS16;dxWizardControlRS16;dxPScxExtCommonRS16;vcldbx;rbDBDE1516;dxNavBarRS16;dclRBE1516;dxSpreadSheetCoreDialogsRS16;rbIDE1516;JvPluginSystem;dxSpreadSheetCoreConditionalFormattingDialogsRS16;cxSchedulerTreeBrowserRS16;DBXOdbcDriver;JvCmp;dxdbtrRS16;madDisAsm_;dxRichEditCoreRS16;JvTimeFramework;dxPSdxDBTVLnkRS16;vclactnband;dxPScxSchedulerLnkRS16;dxServerModeRS16;bindcompvcl;Jcl;vclie;madExcept_;dsnapcon;dxHttpIndyRequestRS16;JvPascalInterpreter;vclx;rbDBE1516;dxFlowChartRS16;dxGDIPlusRS16;JvBDE;dxdborRS16;dxPDFViewerRS16;dxEMFRS16;dxLayoutControlRS16;dxSpreadSheetRS16;dxPScxPivotGridLnkRS16;dxCoreRS16;dxPScxVGridLnkRS16;cxExportRS16;dxPSdxMapControlLnkRS16;dxBarRS16;JvDlgs;cxSchedulerWebServiceStorageRS16;TeeDB;dxDBXServerModeRS16;cxTreeListdxBarPopupMenuRS16;dxPSdxGaugeControlLnkRS16;vclib;inetdbbde;dxRibbonRS16;DBXSybaseASEDriver;dxSpreadSheetConditionalFormattingDialogsRS16;rbTC1516;cxTreeListRS16;vcldsnap;X2CLGL;dxGaugeControlRS16;DBXDb2Driver;dclRBBDE1516;rbDB1516;JvCore;vcl;DBXMSSQLDriver;JvAppFrm;cxSchedulerGridRS16;dxRichEditControlCoreRS16;webdsnap;dxtrmdRS16;rbRIDE1516;JvDocking;adortl;JvWizards;dxRichEditControlRS16;rbADO1516;madBasic_;JvHMI;dxRichEditDocumentModelRS16;JvBands;dxPSdxDBOCLnkRS16;Tee;rbUSERDesign1516;JvSystem;svnui;cxPivotGridChartRS16;JvControls;dxmdsRS16;dxSpellCheckerRS16;dxMapControlRS16;cxGridRS16;dxPScxCommonRS16;dxPSPrVwRibbonRS16;cxEditorsRS16;TeeUI;cxPivotGridRS16;rbUSER1516;JvJans;JvPrintPreview;JvPageComps;dclRBDBE1516;JvStdCtrls;JvCustom;cxSchedulerRibbonStyleEventEditorRS16;rbBDE1516;cxSchedulerRS16;vcltouch;websnap;dxFlowChartAdvancedCustomizeFormRS16;VclSmp;dxTabbedMDIRS16;dxPSRichEditControlLnkRS16;DataSnapConnectors;dxPSdxOCLnkRS16;dxPSdxFCLnkRS16;dxThemeRS16;JclVcl;dxPScxPCProdRS16;rbCIDE1516;svn;bdertl;VirtualTreesR;dxAuthorizationAgentsRS16;dxBarDBNavRS16;$(DCC_UsePackage) + true + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + 1033 + $(BDS)\bin\default_app.manifest + + + DEBUG;$(DCC_Define) + false + true + true + true + + + bin\win32 + true + $(BDS)\bin\default_app.manifest + lib\win32 + 1033 + false + + + false + RELEASE;$(DCC_Define) + 0 + false + + + bin\win32 + true + $(BDS)\bin\default_app.manifest + 1033 + lib\win32 + + + + MainSource + + +
MainForm
+
+ + + + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + +
+ + Delphi.Personality.12 + + + + + DelphiLuaInteractiveTests.dpr + + + False + False + 1 + 0 + 0 + 0 + False + False + False + False + False + 1043 + 1252 + + + + + 1.0.0.0 + + + + + + 1.0.0.0 + + + + + + False + True + + + 12 + + + +
diff --git a/InteractiveTests/DelphiLuaInteractiveTests.res b/InteractiveTests/DelphiLuaInteractiveTests.res new file mode 100644 index 0000000..c287ee9 Binary files /dev/null and b/InteractiveTests/DelphiLuaInteractiveTests.res differ diff --git a/InteractiveTests/MainFrm.dfm b/InteractiveTests/MainFrm.dfm new file mode 100644 index 0000000..96c0caa --- /dev/null +++ b/InteractiveTests/MainFrm.dfm @@ -0,0 +1,114 @@ +object MainForm: TMainForm + Left = 0 + Top = 0 + Caption = 'DelphiLua Interactive Test' + ClientHeight = 547 + ClientWidth = 678 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + Position = poDesktopCenter + OnDestroy = FormDestroy + PixelsPerInch = 96 + TextHeight = 13 + object PageControl: TPageControl + AlignWithMargins = True + Left = 8 + Top = 8 + Width = 662 + Height = 416 + Margins.Left = 8 + Margins.Top = 8 + Margins.Right = 8 + Margins.Bottom = 8 + ActivePage = FunctionReferenceTab + Align = alClient + TabOrder = 0 + object FunctionReferenceTab: TTabSheet + Caption = 'Function reference' + object FunctionReferenceRichEdit: TRichEdit + AlignWithMargins = True + Left = 8 + Top = 49 + Width = 638 + Height = 331 + Margins.Left = 8 + Margins.Top = 8 + Margins.Right = 8 + Margins.Bottom = 8 + Align = alClient + Font.Charset = ANSI_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Courier New' + Font.Style = [] + Lines.Strings = ( + 'function engine.onStartup()' + ' engine.myFunction()' + ' engine.display.log("Hello from display.log!")' + 'end' + '' + '' + 'function engine.myFunction()' + ' print("Hello from myFunction!")' + ' engine.display.log("Hello from myFunction'#39's display.log!")' + 'end') + ParentFont = False + ScrollBars = ssBoth + TabOrder = 1 + end + object FunctionReferenceButtonPanel: TPanel + Left = 0 + Top = 0 + Width = 654 + Height = 41 + Align = alTop + BevelOuter = bvNone + TabOrder = 0 + object FunctionReferenceGetButton: TButton + Left = 8 + Top = 13 + Width = 121 + Height = 25 + Caption = 'Lookup functions' + TabOrder = 0 + OnClick = FunctionReferenceGetButtonClick + end + object FunctionReferenceCallStartupButton: TButton + Left = 135 + Top = 13 + Width = 121 + Height = 25 + Caption = 'Call onStartup' + TabOrder = 1 + OnClick = FunctionReferenceCallStartupButtonClick + end + end + end + end + object LogRichEdit: TRichEdit + AlignWithMargins = True + Left = 8 + Top = 432 + Width = 662 + Height = 107 + Margins.Left = 8 + Margins.Top = 0 + Margins.Right = 8 + Margins.Bottom = 8 + Align = alBottom + Font.Charset = ANSI_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + ParentFont = False + ReadOnly = True + ScrollBars = ssVertical + TabOrder = 1 + end +end diff --git a/InteractiveTests/MainFrm.pas b/InteractiveTests/MainFrm.pas new file mode 100644 index 0000000..c86882c --- /dev/null +++ b/InteractiveTests/MainFrm.pas @@ -0,0 +1,128 @@ +unit MainFrm; + +interface +uses + System.Classes, + Vcl.ComCtrls, + Vcl.Controls, + Vcl.ExtCtrls, + Vcl.Forms, + Vcl.StdCtrls, + + Lua; + + +type + TMainForm = class(TForm) + PageControl: TPageControl; + FunctionReferenceTab: TTabSheet; + FunctionReferenceRichEdit: TRichEdit; + LogRichEdit: TRichEdit; + FunctionReferenceButtonPanel: TPanel; + FunctionReferenceGetButton: TButton; + FunctionReferenceCallStartupButton: TButton; + + procedure FormDestroy(Sender: TObject); + procedure FunctionReferenceGetButtonClick(Sender: TObject); + procedure FunctionReferenceCallStartupButtonClick(Sender: TObject); + private + FFunctionReferenceLua: TLua; + FFunctionReferenceEngine: ILuaTable; + FFunctionReferenceEngineDisplay: ILuaTable; + FFunctionReferenceStartup: ILuaFunction; + + procedure CreateLua(var ALua: TLua; ACode: TStrings); + + procedure Log(const AMessage: string); + procedure Print(AContext: ILuaContext); + end; + + +implementation +uses + System.SysUtils; + + +{$R *.dfm} + +{ TMainForm } +procedure TMainForm.FormDestroy(Sender: TObject); +begin + FFunctionReferenceEngineDisplay := nil; + FFunctionReferenceEngine := nil; + FFunctionReferenceStartup := nil; + FreeAndNil(FFunctionReferenceLua); +end; + + +procedure TMainForm.FunctionReferenceGetButtonClick(Sender: TObject); +begin + try + CreateLua(FFunctionReferenceLua, FunctionReferenceRichEdit.Lines); + + Log('Initializing global variable "engine"...'); + FFunctionReferenceEngineDisplay := TLuaTable.Create; + FFunctionReferenceEngineDisplay.SetValue('log', + procedure(Context: ILuaContext) + begin + Log(Context.Parameters.ToString); + end); + + FFunctionReferenceEngine := TLuaTable.Create; + FFunctionReferenceEngine.SetValue('display', FFunctionReferenceEngineDisplay); + + FFunctionReferenceLua.SetGlobalVariable('engine', FFunctionReferenceEngine); + + Log('Running code...'); + FFunctionReferenceLua.Run; + + Log('Reading back global variable "engine"...'); + FFunctionReferenceEngine := FFunctionReferenceLua.GetGlobalVariable('engine').AsTable; + + Log('Reading engine.onStartup...'); + FFunctionReferenceStartup := FFunctionReferenceEngine.GetValue('onStartup').AsFunction; + if not Assigned(FFunctionReferenceStartup) then + begin + Log('Error: onStartup not found!'); + Exit; + end; + + Log('Done.'); + except + on E:Exception do + Log(E.ClassName + ': ' + E.Message); + end; +end; + + +procedure TMainForm.FunctionReferenceCallStartupButtonClick(Sender: TObject); +begin + FFunctionReferenceStartup.Call(); +end; + + +procedure TMainForm.CreateLua(var ALua: TLua; ACode: TStrings); +begin + FreeAndNil(ALua); + Log('Loading Lua code...'); + + ALua := TLua.Create; + ALua.RegisterFunction('print', Print); + + ALua.LoadFromString(ACode.Text, False); +end; + + +procedure TMainForm.Log(const AMessage: string); +begin + LogRichEdit.Lines.Add(AMessage); + LogRichEdit.SelStart := MaxInt; +end; + + +procedure TMainForm.Print(AContext: ILuaContext); +begin + Log(AContext.Parameters.ToString); +end; + +end. diff --git a/UnitTests/.gitignore b/UnitTests/.gitignore deleted file mode 100644 index 9898608..0000000 --- a/UnitTests/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.local -*.identcache