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

@@ -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.