API Remake
This commit is contained in:
166
Source/RuntimeBuilder.Lua.pas
Normal file
166
Source/RuntimeBuilder.Lua.pas
Normal file
@@ -0,0 +1,166 @@
|
||||
unit RuntimeBuilder.Lua;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
System.Classes,System.TypInfo,System.IOUtils,System.Rtti,Winapi.Windows,
|
||||
pLuaObject,pLuaRecord,pLuaTable,uWordList,Lua,LuaObject,LuaWrapper,pLua,RuntimeBuilder;
|
||||
|
||||
type
|
||||
TRTBLuaCompiler=class(TRTBCompiler)
|
||||
protected type
|
||||
TRTBLuaSource=class(TRTBSource)
|
||||
protected type
|
||||
{TRTBLuaFunc=class(TRTBFunc)
|
||||
protected
|
||||
p:Pointer;
|
||||
sb:NativeUInt;
|
||||
public
|
||||
constructor Create(p:Pointer;sb:NativeUInt);
|
||||
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;override;
|
||||
destructor Destroy;override;
|
||||
end;
|
||||
TRTBLuaLib=class(TRTBLib)
|
||||
private type
|
||||
TRTBLuaLibFunc=class(TRTBLuaFunc)
|
||||
public
|
||||
constructor Create(p:Pointer);
|
||||
destructor Destroy;override;
|
||||
end;
|
||||
private
|
||||
filename:string;
|
||||
Lib:NativeUInt;
|
||||
function GetFuntion(Name:string):TRTBFunc;override;
|
||||
public
|
||||
constructor Create(Name:string);
|
||||
destructor Destroy;override;
|
||||
end;}
|
||||
protected
|
||||
FText:string;
|
||||
function GetText:string;override;
|
||||
procedure SetText(S:string);override;
|
||||
public
|
||||
constructor Create(Compiler:TRTBLuaCompiler);
|
||||
function CompilateAsFunc:TRTBFunc;override;
|
||||
//function CompilateAsLib:TRTBLib;override;
|
||||
end;
|
||||
protected
|
||||
Lua:Plua_state;
|
||||
//function GetIncLibs():string;
|
||||
public
|
||||
libs:TStringList;
|
||||
constructor Create();
|
||||
//function LoadLib(Name:string):TRTBLib;
|
||||
function GenNewSrc():TRTBSource;override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses System.SysUtils;
|
||||
|
||||
{constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaFunc.Create(p:Pointer;sb:NativeUInt);
|
||||
begin
|
||||
Self.p:=VirtualAlloc(nil,sb,MEM_COMMIT ,PAGE_EXECUTE_READWRITE);
|
||||
CopyMemory(Self.p,p,sb);
|
||||
Self.sb:=sb;
|
||||
FreeMem(p);
|
||||
end;
|
||||
|
||||
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaFunc.Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;
|
||||
begin
|
||||
end;
|
||||
|
||||
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaFunc.Destroy;
|
||||
begin
|
||||
VirtualFree(p,sb,MEM_RELEASE);
|
||||
p:=nil;
|
||||
end;
|
||||
|
||||
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.TRTBLuaLibFunc.Create(p:Pointer);
|
||||
begin
|
||||
Self.p:=p;
|
||||
end;
|
||||
|
||||
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.TRTBLuaLibFunc.Destroy;
|
||||
begin
|
||||
p:=nil;
|
||||
end;
|
||||
|
||||
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.GetFuntion(Name:string):TRTBFunc;
|
||||
begin
|
||||
Result:=TRTBLuaLibFunc.Create(GetProcAddress(Lib,pwidechar(Name)));
|
||||
end;
|
||||
|
||||
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.Create(Name:string);
|
||||
begin
|
||||
filename:=Name;
|
||||
Lib:=LoadLibrary(pwidechar(Name));
|
||||
end;
|
||||
|
||||
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.Destroy;
|
||||
begin
|
||||
FreeLibrary(Lib);
|
||||
end;}
|
||||
|
||||
function TRTBLuaCompiler.TRTBLuaSource.GetText:string;
|
||||
begin
|
||||
Result:=FText;
|
||||
end;
|
||||
|
||||
procedure TRTBLuaCompiler.TRTBLuaSource.SetText(S:string);
|
||||
begin
|
||||
FText:=S;
|
||||
end;
|
||||
|
||||
constructor TRTBLuaCompiler.TRTBLuaSource.Create(Compiler:TRTBLuaCompiler);
|
||||
begin
|
||||
inherited Create(Compiler);
|
||||
FText:='';
|
||||
end;
|
||||
|
||||
function TRTBLuaCompiler.TRTBLuaSource.CompilateAsFunc:TRTBFunc;
|
||||
begin
|
||||
//lua_(lua_tocfunction());
|
||||
//(Compiler as TRTBLuaCompiler).Lua.RegisterFunction();
|
||||
end;
|
||||
|
||||
(*function TRTBLuaCompiler.TRTBLuaSource.CompilateAsLib:TRTBLib;
|
||||
var
|
||||
templib:string;
|
||||
Res:TLuaResult;
|
||||
begin
|
||||
templib:=TPath.GetTempFileName;
|
||||
Res:=LuaAssembleToFile({$IFDEF CPUX64}'format PE64 DLL'{$ELSE}'format PE DLL'{$ENDIF}+
|
||||
(Compiler as TRTBLuaCompiler).GetIncLibs+sLineBreak+Text,templib,
|
||||
(Compiler as TRTBLuaCompiler).CompilerMem,(Compiler as TRTBLuaCompiler).MaxSteps);
|
||||
if Res.Error<>Lua_OK then
|
||||
raise Exception.Create(Res.OutStr);
|
||||
Result:=TRTBLuaLib.Create(templib);
|
||||
end;*)
|
||||
|
||||
{function TRTBLuaCompiler.GetIncLibs():string;
|
||||
var
|
||||
i:integer;
|
||||
begin
|
||||
Result:='';
|
||||
for i:=0 to libs.count-1 do
|
||||
Result:=Result+sLineBreak+'include '+#39+libs.Strings[i]+#39;
|
||||
end;}
|
||||
|
||||
constructor TRTBLuaCompiler.Create();
|
||||
begin
|
||||
Lua:=luaL_newstate;
|
||||
libs:=TStringList.Create;
|
||||
end;
|
||||
|
||||
{function TRTBLuaCompiler.LoadLib(Name:string):TRTBLib;
|
||||
begin
|
||||
libs.Add(Name);
|
||||
end;}
|
||||
|
||||
function TRTBLuaCompiler.GenNewSrc():TRTBSource;
|
||||
begin
|
||||
Result:=TRTBLuaSource.Create(Self);
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user