This commit is contained in:
2018-06-20 17:24:04 +03:00
parent 242eeead08
commit 35cb759f40
6 changed files with 574 additions and 385 deletions

View File

@@ -15,13 +15,13 @@ type
protected type
TRTBLuaFunc=class(TRTBFunc)
protected
//p:Pointer;
Name:string;
public
//constructor Create(s:string);
//function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;override;
//destructor Destroy;override;
constructor Create(s:string);
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;override;
destructor Destroy;override;
end;
TRTBFasmVar=class(TRTBVar)
TRTBLuaVar=class(TRTBVar)
protected
//p:pointer;
//&Type:TRTBType;
@@ -32,15 +32,14 @@ type
//destructor Destroy;override;
end;
private
//p:Pointer;
//sb:NativeUInt;
State:Plua_State;
//funcs:TDictionary<string,NativeUInt>;
//regvars:TDictionary<string,TPair<NativeUInt,PTypeInfo>>;
//function GetFuntion(Name:string):TRTBFunc;override;
function GetFuntion(Name:string):TRTBFunc;override;
//function GetVar(Name:string):TRTBVar;override;
public
//constructor Create(p:Pointer;sb:NativeUInt;funcs:TDictionary<string,NativeUInt>;regvars:TDictionary<string,TPair<NativeUInt,PTypeInfo>>);
//destructor Destroy;override;
constructor Create(AState:Plua_State);
destructor Destroy;override;
end;
protected
libs:TStringList;
@@ -50,12 +49,12 @@ type
FText:string;
//function GetIncLibs():string;
function GetText:string;override;
procedure SetText(S:string);override;
procedure SetText(const S:string);override;
public
constructor Create(Compiler:TRTBLuaCompiler);
procedure LoadLib(Name:string);override;
procedure UnLoadLib(Name:string);override;
procedure LoadLib(const Name:string);override;
procedure UnLoadLib(const Name:string);override;
//procedure AddNameSpace(Name:string);override;
//procedure DelNameSpace(Name:string);override;
@@ -86,10 +85,16 @@ type
function GenNewSrc():TRTBSource;override;
end;
const
cLuaLangName='Lua';
implementation
uses System.SysUtils;
const
cCurLang=cLuaLangName;
(*constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Create(p:Pointer);
begin
inherited Create();
@@ -361,37 +366,51 @@ begin
FreeLibrary(Lib);
end;*)
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Create(s:string);
begin
Name:=s;
end;
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;
var
i:TValue;
begin
//for i in args do
// TRTBLuaCompiler.TRTBLuaSource.AddToStack();
end;
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Destroy;
begin
end;
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.GetFuntion(Name:string):TRTBFunc;
begin
//lua
//lua_getglobal();
//lua_call();
//Result:=TRTBLuaFunc.Create();
end;
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.Create(AState:Plua_State);
begin
State:=AState;
end;
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.Destroy;
begin
lua_close(State);
end;
function TRTBLuaCompiler.TRTBLuaSource.GetText:string;
begin
Result:=FText;
end;
procedure TRTBLuaCompiler.TRTBLuaSource.SetText(S:string);
procedure TRTBLuaCompiler.TRTBLuaSource.SetText(const 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.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.TRTBLuaSource.Create(Compiler:TRTBLuaCompiler);
begin
inherited Create(Compiler);
@@ -402,12 +421,12 @@ regvars:=TList<TPair<string,PTypeInfo>>.Create;
consts:=TList<TPair<string,TValue>>.Create;
end;
procedure TRTBLuaCompiler.TRTBLuaSource.LoadLib(Name:string);
procedure TRTBLuaCompiler.TRTBLuaSource.LoadLib(const Name:string);
begin
libs.Add(Name);
end;
procedure TRTBLuaCompiler.TRTBLuaSource.UnLoadLib(Name:string);
procedure TRTBLuaCompiler.TRTBLuaSource.UnLoadLib(const Name:string);
begin
with libs do
Delete(IndexOf(Name));
@@ -602,6 +621,7 @@ var
i,sb:NativeUInt;
RegVarDict:TDictionary<string,TPair<NativeUInt,PTypeInfo>>;
p:pointer;
State:Plua_State;
begin
PreDecl:='';
for s in libs do
@@ -620,8 +640,12 @@ with consts do
for i:=0 to Count-1 do
with Items[i] do
ConstParse(Key,Value,PreDecl,base);}
//Result:=TRTBLuaModule.Create(FText,funcs);
State:=luaL_newstate();
if State=nil then
ERTBError.Create(RTBBuildError,cCurLang,self);
luaL_openlibs(State);
luaL_loadbuffer(State,PAnsiChar(FText),length(s),'code');
Result:=TRTBLuaModule.Create(State);
end;
destructor TRTBLuaCompiler.TRTBLuaSource.Destroy;
@@ -635,7 +659,6 @@ end;
constructor TRTBLuaCompiler.Create();
begin
inherited Create();
//Lua:=luaL_newstate;
end;
function TRTBLuaCompiler.GenNewSrc():TRTBSource;