Update Lua Support
This commit is contained in:
@@ -24,20 +24,18 @@ type
|
|||||||
end;
|
end;
|
||||||
TRTBLuaVar=class(TRTBVar)
|
TRTBLuaVar=class(TRTBVar)
|
||||||
protected
|
protected
|
||||||
//p:pointer;
|
State:Plua_State;
|
||||||
//&Type:TRTBType;
|
Name:string;
|
||||||
//procedure SetVal(Val:TValue);override;
|
procedure SetVal(Val:TValue);override;
|
||||||
//function GetVal:TValue;override;
|
function GetVal:TValue;override;
|
||||||
public
|
public
|
||||||
//constructor Create(p:pointer;&Type:TRTBType);
|
constructor Create(Module:TRTBLuaModule;s:string);
|
||||||
//destructor Destroy;override;
|
destructor Destroy;override;
|
||||||
end;
|
end;
|
||||||
private
|
private
|
||||||
State:Plua_State;
|
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;
|
function GetVar(Name:string):TRTBVar;override;
|
||||||
public
|
public
|
||||||
constructor Create(AState:Plua_State);
|
constructor Create(AState:Plua_State);
|
||||||
destructor Destroy;override;
|
destructor Destroy;override;
|
||||||
@@ -73,12 +71,13 @@ type
|
|||||||
//procedure ExportVariable(NameSpace:string;Name:string;var Data);override;
|
//procedure ExportVariable(NameSpace:string;Name:string;var Data);override;
|
||||||
//procedure DelVariable(NameSpace:string;Name:string);override;
|
//procedure DelVariable(NameSpace:string;Name:string);override;
|
||||||
|
|
||||||
//procedure &Register(NameSpace:string;Name:string;&Type:TRTBType);override;
|
procedure &Register(const NameSpace,Name:string;&Type:TRTBType);override;
|
||||||
//procedure UnRegister(NameSpace:string;Name:string);override;
|
procedure UnRegister(const NameSpace,Name:string);override;
|
||||||
//procedure RegisterFunction(NameSpace:string;Name:string);override;
|
procedure RegisterFunction(const NameSpace,Name:string);override;
|
||||||
//procedure UnRegisterFunction(NameSpace:string;Name:string);override;
|
procedure UnRegisterFunction(const NameSpace,Name:string);override;
|
||||||
|
|
||||||
class procedure AddToStack(State:Plua_State;Data:TValue);static;
|
class procedure AddToStack(State:Plua_State;Data:TValue);static;
|
||||||
|
class function GetFromStack(State:Plua_State):TValue;static;
|
||||||
|
|
||||||
function Compilate:TRTBModule;override;
|
function Compilate:TRTBModule;override;
|
||||||
destructor Destroy;override;
|
destructor Destroy;override;
|
||||||
@@ -98,233 +97,6 @@ uses System.SysUtils;
|
|||||||
const
|
const
|
||||||
cCurLang=cLuaLangName;
|
cCurLang=cLuaLangName;
|
||||||
|
|
||||||
(*constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Create(p:Pointer);
|
|
||||||
begin
|
|
||||||
inherited Create();
|
|
||||||
Self.p:=p;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.TRTBFasmFunc.Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;
|
|
||||||
begin
|
|
||||||
{$IFDEF CPUX64}
|
|
||||||
Result:=Invoke(p,args,ccReg,OutType);
|
|
||||||
{$ELSE}
|
|
||||||
case CallType of
|
|
||||||
CRTBCallTypeRegister:Result:=Invoke(p,args,ccReg,OutType);
|
|
||||||
CRTBCallTypeStdCall:Result:=Invoke(p,args,ccStdCall,OutType);
|
|
||||||
CRTBCallTypeCdecl:Result:=Invoke(p,args,ccCdecl,OutType);
|
|
||||||
CRTBCallTypePascal:Result:=Invoke(p,args,ccPascal,OutType);
|
|
||||||
CRTBCallTypeSafeCall:Result:=Invoke(p,args,ccSafeCall,OutType);
|
|
||||||
end;
|
|
||||||
{$ENDIF}
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.TRTBFasmFunc.Destroy;
|
|
||||||
begin
|
|
||||||
p:=nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.TRTBFasmVar.SetVal(Val:TValue);
|
|
||||||
begin
|
|
||||||
if Val.TypeInfo=&Type then
|
|
||||||
Val.ExtractRawData(p);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.TRTBFasmVar.GetVal:TValue;
|
|
||||||
begin
|
|
||||||
TValue.Make(p,&Type,Result);
|
|
||||||
end;
|
|
||||||
|
|
||||||
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.TRTBFasmVar.Create(p:pointer;&Type:TRTBType);
|
|
||||||
begin
|
|
||||||
Self.p:=p;
|
|
||||||
Self.&Type:=&Type;
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.TRTBFasmVar.Destroy;
|
|
||||||
begin
|
|
||||||
p:=nil;
|
|
||||||
&Type:=nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.GetFuntion(Name:string):TRTBFunc;
|
|
||||||
begin
|
|
||||||
Result:=TRTBFasmFunc.Create(PPointer(NativeUInt(funcs.Items[Name])+NativeUInt(p))^);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.GetVar(Name:string):TRTBVar;
|
|
||||||
begin
|
|
||||||
Result:=TRTBFasmVar.Create(PPointer(NativeUInt(regvars.Items[Name].Key)+NativeUInt(p))^,regvars.Items[Name].Value)
|
|
||||||
end;
|
|
||||||
|
|
||||||
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.Create(p:Pointer;sb:NativeUInt;funcs:TDictionary<string,NativeUInt>;regvars:TDictionary<string,TPair<NativeUInt,PTypeInfo>>);
|
|
||||||
begin
|
|
||||||
Self.p:=p;
|
|
||||||
Self.sb:=sb;
|
|
||||||
Self.funcs:=funcs;
|
|
||||||
Self.regvars:=regvars;
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.Destroy;
|
|
||||||
begin
|
|
||||||
VirtualFree(p,sb,MEM_RELEASE);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TRTBFasmCompiler.TRTBFasmSource.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;
|
|
||||||
|
|
||||||
function TRTBFasmCompiler.TRTBFasmSource.GetText:string;
|
|
||||||
begin
|
|
||||||
Result:=FText;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.SetText(S:string);
|
|
||||||
begin
|
|
||||||
FText:=S;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.AddNameSpace(Name:string);
|
|
||||||
begin
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.DelNameSpace(Name:string);
|
|
||||||
label
|
|
||||||
funcscontinue,regvarscontinue,constscontinue;
|
|
||||||
var
|
|
||||||
i,i0:NativeUInt;
|
|
||||||
begin
|
|
||||||
Name:=Name+'.';
|
|
||||||
i:=0;
|
|
||||||
while i<funcs.Count do
|
|
||||||
begin
|
|
||||||
for i0:=1 to length(Name) do
|
|
||||||
if funcs.Strings[i][i0]=Name[i0]then
|
|
||||||
goto funcscontinue;
|
|
||||||
funcs.Delete(i);
|
|
||||||
inc(i);
|
|
||||||
funcscontinue:
|
|
||||||
end;
|
|
||||||
i:=0;
|
|
||||||
while i<regvars.Count do
|
|
||||||
begin
|
|
||||||
for i0:=1 to length(Name) do
|
|
||||||
if regvars.Items[i].Key[i0]=Name[i0]then
|
|
||||||
goto regvarscontinue;
|
|
||||||
regvars.Delete(i);
|
|
||||||
inc(i);
|
|
||||||
regvarscontinue:
|
|
||||||
end;
|
|
||||||
i:=0;
|
|
||||||
while i<consts.Count do
|
|
||||||
begin
|
|
||||||
for i0:=1 to length(Name) do
|
|
||||||
if consts.Items[i].Key[i0]=Name[i0]then
|
|
||||||
goto constscontinue;
|
|
||||||
consts.Delete(i);
|
|
||||||
inc(i);
|
|
||||||
constscontinue:
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.AddType(NameSpace:string;Name:string;&Type:TRTBType);
|
|
||||||
begin
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.DelType(NameSpace:string;Name:string);
|
|
||||||
begin
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.AddConst(NameSpace:string;Name:string;Val:TValue);
|
|
||||||
begin
|
|
||||||
if NameSpace<>'' then
|
|
||||||
consts.Add(TPair<string,TValue>.Create(NameSpace+'.'+Name,Val))
|
|
||||||
else
|
|
||||||
consts.Add(TPair<string,TValue>.Create(Name,Val));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.DelConst(NameSpace:string;Name:string);
|
|
||||||
var
|
|
||||||
i:NativeUInt;
|
|
||||||
begin
|
|
||||||
if NameSpace<>'' then
|
|
||||||
Name:=NameSpace+'.'+Name;
|
|
||||||
if consts.Count<>0 then
|
|
||||||
for i:=0 to consts.Count-1 do
|
|
||||||
if consts.Items[i].Key=Name then
|
|
||||||
begin
|
|
||||||
consts.Delete(i);
|
|
||||||
Break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.AddVariable(NameSpace:string;Name:string;var Data);
|
|
||||||
begin
|
|
||||||
if NameSpace<>'' then
|
|
||||||
consts.Add(TPair<string,TValue>.Create(NameSpace+'.'+Name,addr(Data)))
|
|
||||||
else
|
|
||||||
consts.Add(TPair<string,TValue>.Create(Name,addr(Data)));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.ExportVariable(NameSpace:string;Name:string;var Data);
|
|
||||||
begin
|
|
||||||
if NameSpace<>'' then
|
|
||||||
consts.Add(TPair<string,TValue>.Create(NameSpace+'.'+Name,Addr(Data)))
|
|
||||||
else
|
|
||||||
consts.Add(TPair<string,TValue>.Create(Name,Addr(Data)));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.DelVariable(NameSpace:string;Name:string);
|
|
||||||
begin
|
|
||||||
DelConst(NameSpace,Name);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.&Register(NameSpace:string;Name:string;&Type:TRTBType);
|
|
||||||
begin
|
|
||||||
if NameSpace<>'' then
|
|
||||||
regvars.Add(TPair<string,PTypeInfo>.Create(NameSpace+'.'+Name,&Type))
|
|
||||||
else
|
|
||||||
regvars.Add(TPair<string,PTypeInfo>.Create(Name,&Type));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.UnRegister(NameSpace:string;Name:string);
|
|
||||||
var
|
|
||||||
i:NativeUInt;
|
|
||||||
begin
|
|
||||||
if NameSpace<>'' then
|
|
||||||
Name:=NameSpace+'.'+Name;
|
|
||||||
if regvars.Count<>0 then
|
|
||||||
for i:=0 to regvars.Count-1 do
|
|
||||||
if regvars.Items[i].Key=Name then
|
|
||||||
begin
|
|
||||||
regvars.Delete(i);
|
|
||||||
Break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.RegisterFunction(NameSpace:string;Name:string);
|
|
||||||
begin
|
|
||||||
if NameSpace<>'' then
|
|
||||||
funcs.Add(NameSpace+'.'+Name)
|
|
||||||
else
|
|
||||||
funcs.Add(Name);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TRTBFasmCompiler.TRTBFasmSource.UnRegisterFunction(NameSpace:string;Name:string);
|
|
||||||
var
|
|
||||||
i:NativeUInt;
|
|
||||||
begin
|
|
||||||
if NameSpace<>'' then
|
|
||||||
Name:=NameSpace+'.'+Name;
|
|
||||||
with funcs do
|
|
||||||
Delete(IndexOf(Name));
|
|
||||||
end;
|
|
||||||
|
|
||||||
{constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaFunc.Create(p:Pointer;sb:NativeUInt);
|
{constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaFunc.Create(p:Pointer;sb:NativeUInt);
|
||||||
begin
|
begin
|
||||||
Self.p:=VirtualAlloc(nil,sb,MEM_COMMIT ,PAGE_EXECUTE_READWRITE);
|
Self.p:=VirtualAlloc(nil,sb,MEM_COMMIT ,PAGE_EXECUTE_READWRITE);
|
||||||
@@ -367,31 +139,61 @@ end;
|
|||||||
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.Destroy;
|
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaLib.Destroy;
|
||||||
begin
|
begin
|
||||||
FreeLibrary(Lib);
|
FreeLibrary(Lib);
|
||||||
end;*)
|
end;}
|
||||||
|
|
||||||
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Create(Module:TRTBLuaModule;s:string);
|
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Create(Module:TRTBLuaModule;s:string);
|
||||||
begin
|
begin
|
||||||
Name:=s;
|
Name:=s;
|
||||||
Module:=Module
|
State:=Module.State;
|
||||||
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
|
||||||
|
lua_getfield(State,LUA_GLOBALSINDEX,PAnsiChar(Name));
|
||||||
for i in args do
|
for i in args do
|
||||||
TRTBLuaCompiler.TRTBLuaSource.AddToStack(State,i);
|
TRTBLuaSource.AddToStack(State,i);
|
||||||
|
lua_pcall(State,length(args),1);
|
||||||
|
Result:=TRTBLuaSource.GetFromStack(State);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Destroy;
|
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaFunc.Destroy;
|
||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaVar.SetVal(Val:TValue);
|
||||||
|
begin
|
||||||
|
TRTBLuaSource.AddToStack(State,Val);
|
||||||
|
lua_setfield(State,LUA_GLOBALSINDEX,PAnsiChar(Name));
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaVar.GetVal:TValue;
|
||||||
|
begin
|
||||||
|
lua_getfield(State,LUA_GLOBALSINDEX,PAnsiChar(Name));
|
||||||
|
Result:=TRTBLuaSource.GetFromStack(State);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaVar.Create(Module:TRTBLuaModule;s:string);
|
||||||
|
begin
|
||||||
|
Name:=s;
|
||||||
|
State:=Module.State;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.TRTBLuaVar.Destroy;
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.GetFuntion(Name:string):TRTBFunc;
|
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.GetFuntion(Name:string):TRTBFunc;
|
||||||
begin
|
begin
|
||||||
Result:=TRTBLuaFunc.Create(self,Name);
|
Result:=TRTBLuaFunc.Create(self,Name);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.GetVar(Name:string):TRTBVar;
|
||||||
|
begin
|
||||||
|
Result:=TRTBLuaVar.Create(self,Name);
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.Create(AState:Plua_State);
|
constructor TRTBLuaCompiler.TRTBLuaSource.TRTBLuaModule.Create(AState:Plua_State);
|
||||||
begin
|
begin
|
||||||
State:=AState;
|
State:=AState;
|
||||||
@@ -433,6 +235,22 @@ with libs do
|
|||||||
Delete(IndexOf(Name));
|
Delete(IndexOf(Name));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TRTBLuaCompiler.TRTBLuaSource.&Register(const NameSpace,Name:string;&Type:TRTBType);
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRTBLuaCompiler.TRTBLuaSource.UnRegister(const NameSpace,Name:string);
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRTBLuaCompiler.TRTBLuaSource.RegisterFunction(const NameSpace,Name:string);
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRTBLuaCompiler.TRTBLuaSource.UnRegisterFunction(const NameSpace,Name:string);
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TRTBLuaCompiler.TRTBLuaSource.AddToStack(State:Plua_State;Data:TValue);
|
class procedure TRTBLuaCompiler.TRTBLuaSource.AddToStack(State:Plua_State;Data:TValue);
|
||||||
var
|
var
|
||||||
i:NativeUInt;
|
i:NativeUInt;
|
||||||
@@ -442,7 +260,7 @@ with Data do
|
|||||||
if IsType<AnsiString> or IsType<RawByteString> or IsType<UTF8String> then
|
if IsType<AnsiString> or IsType<RawByteString> or IsType<UTF8String> then
|
||||||
lua_pushstring(State,PAnsiChar(AsType<AnsiString>))
|
lua_pushstring(State,PAnsiChar(AsType<AnsiString>))
|
||||||
else if IsType<ShortString> then
|
else if IsType<ShortString> then
|
||||||
lua_pushstring(State,PAnsiChar(AsType<ShortString>))
|
lua_pushstring(State,PAnsiChar(String(AsType<ShortString>)))
|
||||||
else if IsType<WideString> then
|
else if IsType<WideString> then
|
||||||
lua_pushstring(State,PAnsiChar(AsType<WideString>))
|
lua_pushstring(State,PAnsiChar(AsType<WideString>))
|
||||||
else if IsType<UCS4String> then
|
else if IsType<UCS4String> then
|
||||||
@@ -467,10 +285,10 @@ with Data do
|
|||||||
lua_pushlightuserdata(State,AsType<Pointer>)
|
lua_pushlightuserdata(State,AsType<Pointer>)
|
||||||
else if IsArray then
|
else if IsArray then
|
||||||
begin
|
begin
|
||||||
lua_createtable();
|
lua_createtable(State,Data.GetArrayLength,0);
|
||||||
for i:=0 to Data.GetArrayLength-1 do
|
for i:=0 to Data.GetArrayLength-1 do
|
||||||
begin
|
begin
|
||||||
lua_pushinteger(i);
|
lua_pushinteger(State,i);
|
||||||
AddToStack(State,Data.GetArrayElement(i));
|
AddToStack(State,Data.GetArrayElement(i));
|
||||||
lua_settable(State,-3);
|
lua_settable(State,-3);
|
||||||
end;
|
end;
|
||||||
@@ -478,16 +296,36 @@ with Data do
|
|||||||
else if Data.Kind=tkRecord then
|
else if Data.Kind=tkRecord then
|
||||||
begin
|
begin
|
||||||
rtype:=TRTTIContext.Create.GetType(Data.TypeInfo);
|
rtype:=TRTTIContext.Create.GetType(Data.TypeInfo);
|
||||||
|
|
||||||
end
|
end
|
||||||
//else //if Value.Kind=tkUnknown then
|
//else if Data.Kind=tkUnknown then
|
||||||
//PreDecl:=PreDecl+Key+': times '+ Value.DataSize.ToString+' db 0'+sLineBreak;
|
// PreDecl:=PreDecl+Key+': times '+ Value.DataSize.ToString+' db 0'+sLineBreak;
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
//lua_pushlightuserdata(State,);
|
//lua_pushlightuserdata(State,);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TRTBLuaCompiler.TRTBLuaSource.GetFromStack(State:Plua_State):TValue;
|
||||||
|
begin
|
||||||
|
case lua_type(State,-1) of
|
||||||
|
LUA_TNIL: Result:=TValue.Empty;
|
||||||
|
LUA_TBOOLEAN: Result:=lua_toboolean(State,-1);
|
||||||
|
LUA_TLIGHTUSERDATA: Result:=lua_touserdata(State,-1);
|
||||||
|
LUA_TNUMBER:
|
||||||
|
begin
|
||||||
|
Result:=lua_tonumber(State,-1);
|
||||||
|
if Result.AsType<lua_Number> =Round(Result.AsType<lua_Number>) then
|
||||||
|
Result:=Round(Result.AsType<lua_Number>)
|
||||||
|
end;
|
||||||
|
LUA_TSTRING:Result:=lua_tostring(State,-1);
|
||||||
|
//LUA_TTABLE:Result:=lua_totable(State,-1);
|
||||||
|
//LUA_TFUNCTION:Result:=lua_tostring(State,-1);
|
||||||
|
LUA_TUSERDATA:Result:=lua_touserdata(State,-1);
|
||||||
|
LUA_TTHREAD:Result:=TValue.From<Plua_State>(lua_tothread(State,-1));
|
||||||
|
end;
|
||||||
|
lua_pop(State,1);
|
||||||
|
end;
|
||||||
|
|
||||||
function TRTBLuaCompiler.TRTBLuaSource.Compilate:TRTBModule;
|
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
|
||||||
@@ -569,7 +407,7 @@ function TRTBLuaCompiler.TRTBLuaSource.Compilate:TRTBModule;
|
|||||||
begin
|
begin
|
||||||
PreDecl:=PreDecl+Key+':'+sLineBreak;
|
PreDecl:=PreDecl+Key+':'+sLineBreak;
|
||||||
for i:=0 to Value.GetArrayLength-1 do
|
for i:=0 to Value.GetArrayLength-1 do
|
||||||
VarParse(key+'.i'+i.ToString,Value.GetArrayElement(i),PreDecl,Base);
|
//VarParse(key+'.i'+i.ToString,Value.GetArrayElement(i),PreDecl,Base);
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else //if Value.Kind=tkUnknown then
|
else //if Value.Kind=tkUnknown then
|
||||||
|
|||||||
Binary file not shown.
@@ -86,17 +86,17 @@ Src.Text:='function main(n)'+sLineBreak+' return n'+sLineBreak+'end';
|
|||||||
//Src.RegisterFunction('','varmain');
|
//Src.RegisterFunction('','varmain');
|
||||||
//Src.Register('','Pmain',TypeInfo(integer));
|
//Src.Register('','Pmain',TypeInfo(integer));
|
||||||
Module:=Src.Compilate;
|
Module:=Src.Compilate;
|
||||||
//Func1:=Module.Funtion['main'];
|
Func1:=Module.Funtion['main'];
|
||||||
//Func2:=Module.Funtion['varmain'];
|
//Func2:=Module.Funtion['varmain'];
|
||||||
//if 1<>Func1.Call(TypeInfo(integer),[454],CRTBCallTypeStdCall).AsInteger then
|
if 1<>Func1.Call(TypeInfo(integer),[454],CRTBCallTypeStdCall).AsInteger then
|
||||||
// raise Exception.Create('Error in LuaTest');
|
raise Exception.Create('Error in LuaTest');
|
||||||
//Var1:=Module.&Var['Pmain'];
|
//Var1:=Module.&Var['Pmain'];
|
||||||
//Var1.Val:=424;
|
//Var1.Val:=424;
|
||||||
//if Var1.Val.AsInteger<>Func2.Call(TypeInfo(integer),[],CRTBCallTypeStdCall).AsInteger then
|
//if Var1.Val.AsInteger<>Func2.Call(TypeInfo(integer),[],CRTBCallTypeStdCall).AsInteger then
|
||||||
// raise Exception.Create('Error in LuaTest');
|
// raise Exception.Create('Error in LuaTest');
|
||||||
//FreeAndNil(Var1);
|
//FreeAndNil(Var1);
|
||||||
//FreeAndNil(Func2);
|
//FreeAndNil(Func2);
|
||||||
//FreeAndNil(Func1);
|
FreeAndNil(Func1);
|
||||||
FreeAndNil(module);
|
FreeAndNil(module);
|
||||||
FreeAndNil(Src);
|
FreeAndNil(Src);
|
||||||
FreeAndNil(Lua);
|
FreeAndNil(Lua);
|
||||||
|
|||||||
Submodule lib/pLua-XE updated: 79883e7f4e...a5a7ab28f0
Reference in New Issue
Block a user