Add lua implementation

This commit is contained in:
2018-05-06 21:19:46 +03:00
parent 512e9c9d04
commit 88cfa48d24
6 changed files with 601 additions and 97 deletions

View File

@@ -15,7 +15,7 @@ uses
RuntimeBuilder in '..\Source\RuntimeBuilder.pas',
RuntimeBuilder.Fasm in '..\Source\RuntimeBuilder.Fasm.pas',
FasmOnDelphi in '..\lib\FasmOnDelphi\Source\FasmOnDelphi.pas',
Fasm4Delphi in '..\lib\FasmOnDelphi\Fasm4Delphi\Source\Fasm4Delphi.pas'{,
Fasm4Delphi in '..\lib\FasmOnDelphi\Fasm4Delphi\Source\Fasm4Delphi.pas',
RuntimeBuilder.Lua in '..\Source\RuntimeBuilder.Lua.pas',
pLuaObject in '..\lib\pLua-XE\src\pLuaObject.pas',
pLuaRecord in '..\lib\pLua-XE\src\pLuaRecord.pas',
@@ -24,7 +24,7 @@ uses
Lua in '..\lib\pLua-XE\src\Lua.pas',
LuaObject in '..\lib\pLua-XE\src\LuaObject.pas',
LuaWrapper in '..\lib\pLua-XE\src\LuaWrapper.pas',
pLua in '..\lib\pLua-XE\src\pLua.pas'{};
pLua in '..\lib\pLua-XE\src\pLua.pas';
var
runner : ITestRunner;

View File

@@ -109,8 +109,26 @@
Lua in '..\lib\pLua-XE\src\Lua.pas',
LuaObject in '..\lib\pLua-XE\src\LuaObject.pas',
LuaWrapper in '..\lib\pLua-XE\src\LuaWrapper.pas',
pLua in &apos;..\lib\pLua-XE\src\pLua.pas&apos;{</Form>
pLua in &apos;..\lib\pLua-XE\src\pLua.pas&apos;;
var
runner</Form>
<DesignClass>ITestRunner;
results : IRunResults;
logger : ITestLogger;
nunitLogger : ITestLogger;
begin
{$IFDEF TESTINSIGHT</DesignClass>
</DCCReference>
<DCCReference Include="..\Source\RuntimeBuilder.Lua.pas"/>
<DCCReference Include="..\lib\pLua-XE\src\pLuaObject.pas"/>
<DCCReference Include="..\lib\pLua-XE\src\pLuaRecord.pas"/>
<DCCReference Include="..\lib\pLua-XE\src\pLuaTable.pas"/>
<DCCReference Include="..\lib\pLua-XE\src\uWordList.pas"/>
<DCCReference Include="..\lib\pLua-XE\src\Lua.pas"/>
<DCCReference Include="..\lib\pLua-XE\src\LuaObject.pas"/>
<DCCReference Include="..\lib\pLua-XE\src\LuaWrapper.pas"/>
<DCCReference Include="..\lib\pLua-XE\src\pLua.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
@@ -467,13 +485,13 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
</Deployment>
<Platforms>
<Platform value="OSX32">False</Platform>

View File

@@ -3,21 +3,21 @@ unit Unit1;
interface
uses
System.SysUtils,DUnitX.TestFramework,RuntimeBuilder,RuntimeBuilder.Fasm;
System.SysUtils,DUnitX.TestFramework,RuntimeBuilder,RuntimeBuilder.Fasm,RuntimeBuilder.Lua;
type
[TestFixture]
TRuntimeBuilderTestObject=class(TObject)
public
[TestCase]
procedure Test1();
procedure FasmTest();
[TestCase]
procedure Test2();
procedure LuaTest();
end;
implementation
procedure TRuntimeBuilderTestObject.Test1();
procedure TRuntimeBuilderTestObject.FasmTest();
var
Fasm:TRTBFasmCompiler;
Src:TRTBSource;
@@ -36,18 +36,18 @@ Module:=Src.Compilate;
Func1:=Module.Funtion['main'];
Func2:=Module.Funtion['varmain'];
if 454<>Func1.Call(TypeInfo(integer),[454],CRTBCallTypeStdCall).AsInteger then
raise Exception.Create('Error in test1');
raise Exception.Create('Error in FasmTest');
Var1:=Module.&Var['Pmain'];
Var1.Val:=424;
if Var1.Val.AsInteger<>Func2.Call(TypeInfo(integer),[],CRTBCallTypeStdCall).AsInteger then
raise Exception.Create('Error in test1');
raise Exception.Create('Error in FasmTest');
FreeAndNil(Var1);
FreeAndNil(Func2);
FreeAndNil(Func1);
FreeAndNil(module);
FreeAndNil(Src);
FreeAndNil(Fasm);
end;
procedure TRuntimeBuilderTestObject.Test2();
var
{var
Fasm:TRTBFasmCompiler;
Src:TRTBSource;
Func1:TRTBFunc;
@@ -67,6 +67,37 @@ FreeAndNil(Src);
FreeAndNil(Fasm);}
end;
procedure TRuntimeBuilderTestObject.LuaTest();
var
Lua:TRTBLuaCompiler;
Src:TRTBSource;
Module:TRTBModule;
Func1,Func2:TRTBFunc;
Var1:TRTBVar;
begin
Lua:=TRTBLuaCompiler.Create();
Src:=Lua.GenNewSrc;
Src.Text:='function main(n)'+sLineBreak+' return 1'+sLineBreak+'end';
Src.RegisterFunction('','main');
//Src.RegisterFunction('','varmain');
//Src.Register('','Pmain',TypeInfo(integer));
Module:=Src.Compilate;
Func1:=Module.Funtion['main'];
//Func2:=Module.Funtion['varmain'];
if 454<>Func1.Call(TypeInfo(integer),[454],CRTBCallTypeStdCall).AsInteger then
raise Exception.Create('Error in LuaTest');
//Var1:=Module.&Var['Pmain'];
//Var1.Val:=424;
//if Var1.Val.AsInteger<>Func2.Call(TypeInfo(integer),[],CRTBCallTypeStdCall).AsInteger then
// raise Exception.Create('Error in LuaTest');
FreeAndNil(Var1);
FreeAndNil(Func2);
FreeAndNil(Func1);
FreeAndNil(module);
FreeAndNil(Src);
FreeAndNil(Lua);
end;
initialization
TDUnitX.RegisterTestFixture(TRuntimeBuilderTestObject);
end.

View File

@@ -1,29 +0,0 @@
entry DllEntryPoint
section '.text' code readable executable
proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
mov eax,TRUE
ret
endp
proc MyEcho HWnd
mov eax,[HWnd]
ret
endp
dd GetLastError
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL'
import kernel,\
GetLastError,'GetLastError'
section '.edata' export data readable
export '1.DLL',\
MyEcho,'MyEcho'
section '.reloc' fixups data readable discardable