unit Unit1; interface uses System.SysUtils,DUnitX.TestFramework,RuntimeBuilder,RuntimeBuilder.Fasm,RuntimeBuilder.Lua; type [TestFixture] TRuntimeBuilderTestObject=class(TObject) public [TestCase] procedure FasmTest(); [TestCase] procedure LuaTest(); end; implementation procedure TRuntimeBuilderTestObject.FasmTest(); var Fasm:TRTBFasmCompiler; Src:TRTBSource; Module:TRTBModule; Func1,Func2,Func3:TRTBFunc; Var1:TRTBVar; begin Fasm:=TRTBFasmCompiler.Create('..\..\..\lib\FasmOnDelphi\fasmw172\fasm'); Src:=Fasm.GenNewSrc; with Src do begin Text:='main:'+sLineBreak+ 'pop ecx'+sLineBreak+ 'pop eax'+sLineBreak+ 'jmp ecx'+sLineBreak+ 'Pmain dd 0'+sLineBreak+ 'varmain:'+sLineBreak+ 'mov eax,[Pmain]'+sLineBreak+ 'ret'+sLineBreak+ 'callbacktest:'+sLineBreak+ 'push 80'+sLineBreak+ 'call CallBack'+sLineBreak+ 'ret'; RegisterFunction('','main'); RegisterFunction('','varmain'); RegisterFunction('','callbacktest'); AddCallBack('','CallBack',function(arg:array of const):TRTBCallBackOut begin Result:=arg[0]; end); Register('','Pmain',TypeInfo(integer)); end; Module:=Src.Compilate; Func1:=Module.Funtion['main']; Func2:=Module.Funtion['varmain']; Func3:=Module.Funtion['callbacktest']; if 454<>Func1.Call(TypeInfo(integer),[454],CRTBCallTypeStdCall).AsInteger then 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 FasmTest'); if PByte(Func3.Call(TypeInfo(integer),[],CRTBCallTypeStdCall).AsInteger)^<>80 then raise Exception.Create('Error in FasmTest'); FreeAndNil(Var1); FreeAndNil(Func3); FreeAndNil(Func2); FreeAndNil(Func1); FreeAndNil(module); 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 n'+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 1<>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.