Update Lua Support
This commit is contained in:
@@ -15,9 +15,10 @@ type
|
|||||||
protected type
|
protected type
|
||||||
TRTBLuaFunc=class(TRTBFunc)
|
TRTBLuaFunc=class(TRTBFunc)
|
||||||
protected
|
protected
|
||||||
|
State:Plua_State;
|
||||||
Name:string;
|
Name:string;
|
||||||
public
|
public
|
||||||
constructor Create(s:string);
|
constructor Create(Module:TRTBLuaModule;s:string);
|
||||||
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;override;
|
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;override;
|
||||||
destructor Destroy;override;
|
destructor Destroy;override;
|
||||||
end;
|
end;
|
||||||
@@ -77,6 +78,8 @@ type
|
|||||||
//procedure RegisterFunction(NameSpace:string;Name:string);override;
|
//procedure RegisterFunction(NameSpace:string;Name:string);override;
|
||||||
//procedure UnRegisterFunction(NameSpace:string;Name:string);override;
|
//procedure UnRegisterFunction(NameSpace:string;Name:string);override;
|
||||||
|
|
||||||
|
class procedure AddToStack(State:Plua_State;Data:TValue);static;
|
||||||
|
|
||||||
function Compilate:TRTBModule;override;
|
function Compilate:TRTBModule;override;
|
||||||
destructor Destroy;override;
|
destructor Destroy;override;
|
||||||
end;
|
end;
|
||||||
@@ -366,17 +369,18 @@ begin
|
|||||||
FreeLibrary(Lib);
|
FreeLibrary(Lib);
|
||||||
end;*)
|
end;*)
|
||||||
|
|
||||||
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Create(s:string);
|
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Create(Module:TRTBLuaModule;s:string);
|
||||||
begin
|
begin
|
||||||
Name:=s;
|
Name:=s;
|
||||||
|
Module:=Module
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;
|
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;
|
||||||
var
|
var
|
||||||
i:TValue;
|
i:TValue;
|
||||||
begin
|
begin
|
||||||
//for i in args do
|
for i in args do
|
||||||
// TRTBLuaCompiler.TRTBLuaSource.AddToStack();
|
TRTBLuaCompiler.TRTBLuaSource.AddToStack(State,i);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Destroy;
|
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Destroy;
|
||||||
@@ -385,10 +389,7 @@ end;
|
|||||||
|
|
||||||
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.GetFuntion(Name:string):TRTBFunc;
|
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.GetFuntion(Name:string):TRTBFunc;
|
||||||
begin
|
begin
|
||||||
//lua
|
Result:=TRTBLuaFunc.Create(self,Name);
|
||||||
//lua_getglobal();
|
|
||||||
//lua_call();
|
|
||||||
//Result:=TRTBLuaFunc.Create();
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.Create(AState:Plua_State);
|
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.Create(AState:Plua_State);
|
||||||
@@ -432,104 +433,62 @@ with libs do
|
|||||||
Delete(IndexOf(Name));
|
Delete(IndexOf(Name));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TRTBLuaCompiler.TRTBLuaSource.Compilate:TRTBModule;
|
class procedure TRTBLuaCompiler.TRTBLuaSource.AddToStack(State:Plua_State;Data:TValue);
|
||||||
procedure VarParse(key:string;value:TValue;var PreDecl:string;var base:NativeUInt);
|
|
||||||
var
|
var
|
||||||
i:NativeUInt;
|
i:NativeUInt;
|
||||||
p0:PByte;
|
rtype:TRTTIType;
|
||||||
begin
|
begin
|
||||||
if Value.IsType<AnsiString> or Value.IsType<RawByteString> or Value.IsType<UTF8String> then
|
with Data do
|
||||||
|
if IsType<AnsiString> or IsType<RawByteString> or IsType<UTF8String> then
|
||||||
|
lua_pushstring(State,PAnsiChar(AsType<AnsiString>))
|
||||||
|
else if IsType<ShortString> then
|
||||||
|
lua_pushstring(State,PAnsiChar(AsType<ShortString>))
|
||||||
|
else if IsType<WideString> then
|
||||||
|
lua_pushstring(State,PAnsiChar(AsType<WideString>))
|
||||||
|
else if IsType<UCS4String> then
|
||||||
|
lua_pushstring(State,PAnsiChar(AsType<UCS4String>))
|
||||||
|
else if IsOrdinal then
|
||||||
|
lua_pushinteger(State,Data.AsOrdinal)
|
||||||
|
else if IsType<Single> then
|
||||||
|
lua_pushnumber(State,AsType<Single>)
|
||||||
|
else if IsType<Double> then
|
||||||
|
lua_pushnumber(State,AsType<Double>)
|
||||||
|
else if IsType<Extended> then
|
||||||
|
lua_pushnumber(State,AsExtended)
|
||||||
|
else if IsType<Real> then
|
||||||
|
lua_pushnumber(State,AsExtended)
|
||||||
|
else if IsType<Real48> then
|
||||||
|
lua_pushnumber(State,AsType<Real48>)
|
||||||
|
else if IsType<Comp> then
|
||||||
|
lua_pushnumber(State,AsType<Comp>)
|
||||||
|
else if IsType<Currency> then
|
||||||
|
lua_pushnumber(State,AsType<Currency>)
|
||||||
|
else if Kind=tkPointer then
|
||||||
|
lua_pushlightuserdata(State,AsType<Pointer>)
|
||||||
|
else if IsArray then
|
||||||
begin
|
begin
|
||||||
PreDecl:=PreDecl+Key+' db '+#39+Value.AsType<AnsiString>+#39+',0'+sLineBreak;
|
lua_createtable();
|
||||||
inc(base,length(Value.AsType<AnsiString>));
|
for i:=0 to Data.GetArrayLength-1 do
|
||||||
end
|
|
||||||
else if Value.IsType<ShortString> then
|
|
||||||
begin
|
begin
|
||||||
PreDecl:=PreDecl+Key+' db '+#39+Value.AsType<ShortString>+#39+',0'+sLineBreak;
|
lua_pushinteger(i);
|
||||||
inc(base,length(Value.AsType<ShortString>));
|
AddToStack(State,Data.GetArrayElement(i));
|
||||||
end
|
lua_settable(State,-3);
|
||||||
else if Value.IsType<WideString> then
|
|
||||||
begin
|
|
||||||
PreDecl:=PreDecl+Key+' db ';
|
|
||||||
p0:=Pointer(PWideChar(Value.AsType<WideString>));
|
|
||||||
for i:={$IFDEF NEXTGEN}0{$ELSE}1{$ENDIF} to length(Value.AsType<WideString>){$IFDEF NEXTGEN}-1{$ENDIF} do
|
|
||||||
begin
|
|
||||||
PreDecl:=PreDecl+inttostr(p0^)+',';
|
|
||||||
inc(p0);
|
|
||||||
PreDecl:=PreDecl+inttostr(p0^)+',';
|
|
||||||
inc(p0);
|
|
||||||
end;
|
|
||||||
PreDecl:=PreDecl+'0,0'+sLineBreak;
|
|
||||||
inc(base,length(Value.AsType<WideString>)*2);
|
|
||||||
end
|
|
||||||
else if Value.IsType<UCS4String> then
|
|
||||||
begin
|
|
||||||
PreDecl:=PreDecl+Key+' db ';
|
|
||||||
p0:=Pointer(PWideChar(Value.AsType<UCS4String>));
|
|
||||||
for i:={$IFDEF NEXTGEN}0{$ELSE}1{$ENDIF} to length(Value.AsType<UCS4String>){$IFDEF NEXTGEN}-1{$ENDIF} do
|
|
||||||
begin
|
|
||||||
PreDecl:=PreDecl+inttostr(p0^)+',';
|
|
||||||
inc(p0);
|
|
||||||
PreDecl:=PreDecl+inttostr(p0^)+',';
|
|
||||||
inc(p0);
|
|
||||||
PreDecl:=PreDecl+inttostr(p0^)+',';
|
|
||||||
inc(p0);
|
|
||||||
PreDecl:=PreDecl+inttostr(p0^)+',';
|
|
||||||
inc(p0);
|
|
||||||
end;
|
|
||||||
PreDecl:=PreDecl+'0,0,0,0'+sLineBreak;
|
|
||||||
inc(base,length(Value.AsType<UCS4String>)*4);
|
|
||||||
end
|
|
||||||
else if Value.IsOrdinal then
|
|
||||||
case Value.DataSize of
|
|
||||||
1:PreDecl:=PreDecl+Key+' db '+Value.AsOrdinal.ToString+sLineBreak;
|
|
||||||
2:PreDecl:=PreDecl+Key+' dw '+Value.AsOrdinal.ToString+sLineBreak;
|
|
||||||
4:PreDecl:=PreDecl+Key+' dd '+Value.AsOrdinal.ToString+sLineBreak;
|
|
||||||
8:PreDecl:=PreDecl+Key+' dq '+Value.AsOrdinal.ToString+sLineBreak;
|
|
||||||
end
|
|
||||||
else if Value.Kind=tkFloat then
|
|
||||||
begin
|
|
||||||
if Value.IsType<Single> then
|
|
||||||
PreDecl:=PreDecl+Key+' dd '+FloatToStrF(Value.AsType<Single>,ffFixed,1000,1000)+sLineBreak
|
|
||||||
else if Value.IsType<Double> then
|
|
||||||
PreDecl:=PreDecl+Key+' dq '+FloatToStrF(Value.AsType<Double>,ffFixed,1000,1000)+sLineBreak
|
|
||||||
else if Value.IsType<Extended> then
|
|
||||||
PreDecl:=PreDecl+Key+{$IF 8=SizeOf(Extended)}' dq '{$ELSEIF 10=SizeOf(Extended)}' dt '{$ELSE}' ddq '{$IFEND}+FloatToStrF(Value.AsType<Extended>,ffFixed,1000,1000)+sLineBreak
|
|
||||||
else if Value.IsType<Real> then
|
|
||||||
PreDecl:=PreDecl+Key+' dq '+FloatToStrF(Value.AsType<Real>,ffFixed,1000,1000)+sLineBreak
|
|
||||||
else if Value.IsType<Real48> then
|
|
||||||
PreDecl:=PreDecl+Key+' df '+FloatToStrF(Value.AsType<Real48>,ffFixed,1000,1000)+sLineBreak
|
|
||||||
else if Value.IsType<Comp> then
|
|
||||||
PreDecl:=PreDecl+Key+' dq '+FloatToStrF(Value.AsType<Comp>,ffFixed,1000,1000)+sLineBreak
|
|
||||||
else if Value.IsType<Currency> then
|
|
||||||
PreDecl:=PreDecl+Key+' dq '+FloatToStrF(Value.AsType<Currency>,ffFixed,1000,1000)+sLineBreak
|
|
||||||
else
|
|
||||||
PreDecl:=PreDecl+Key+' dd 0.0'+sLineBreak;
|
|
||||||
end
|
|
||||||
else if Value.Kind=tkPointer then
|
|
||||||
PreDecl:=PreDecl+Key+' equ '+NativeUInt(Value.AsType<Pointer>).ToString+sLineBreak
|
|
||||||
else if Value.IsArray then
|
|
||||||
begin
|
|
||||||
if Value.GetArrayLength=0 then
|
|
||||||
begin
|
|
||||||
PreDecl:=PreDecl+Key+' equ 0'+sLineBreak;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
PreDecl:=PreDecl+Key+':'+sLineBreak;
|
|
||||||
for i:=0 to Value.GetArrayLength-1 do
|
|
||||||
VarParse(key+'.i'+i.ToString,Value.GetArrayElement(i),PreDecl,Base);
|
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
{else if Value.Kind=tkRecord then
|
else if Data.Kind=tkRecord then
|
||||||
begin
|
begin
|
||||||
PreDecl:=PreDecl+Key+':'+sLineBreak;
|
rtype:=TRTTIContext.Create.GetType(Data.TypeInfo);
|
||||||
for i:=1 to Value.TypeData.ManagedFldCount do
|
|
||||||
|
|
||||||
end}
|
end
|
||||||
else //if Value.Kind=tkUnknown then
|
//else //if Value.Kind=tkUnknown then
|
||||||
PreDecl:=PreDecl+Key+': times '+ Value.DataSize.ToString+' db 0'+sLineBreak;
|
//PreDecl:=PreDecl+Key+': times '+ Value.DataSize.ToString+' db 0'+sLineBreak;
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
//lua_pushlightuserdata(State,);
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRTBLuaCompiler.TRTBLuaSource.Compilate:TRTBModule;
|
||||||
procedure ConstParse(key:string;value:TValue;var PreDecl:string;var base:NativeUInt);
|
procedure ConstParse(key:string;value:TValue;var PreDecl:string;var base:NativeUInt);
|
||||||
var
|
var
|
||||||
i:NativeUInt;
|
i:NativeUInt;
|
||||||
|
|||||||
Reference in New Issue
Block a user