I have Lua tables that have to pass data to Pascal. Below is the method that I'm currently using.
Lua Code:
local ffi=require("ffi")
ffi.cdef[[
void __cdecl Print(char * S);
void __cdecl Func1(struct structLIST *struct1);
#pragma pack(1)
typedef struct structLIST {
int val1;
char* val2;
} structLIST1;
#pragma pack(8)
]]
local str=ffi.new("char[?]",1000)
local tableIndex = {}
local strVal
local valStr= "Enter in loop"
for k,v in pairs(TABLE1) do
tableIndex=v
local outRes = ffi.new("structLIST1[1]")
for k2, v2 in pairs(tableIndex) do
ffi.copy(str, valStr)
ffi.C.Print(str)
if k2=='val1' then
outRes[0].val1= tonumber(v2)
elseif k2=='val2' then
outRes[0].val2= ffi.string(v2)
end
end
ffi.C.Print(str)]]
end
Pascal Code:
type
TSTRUCT_RECORD = packed record
val1:integer;
val2 : PChar;
end;
procedure Print( S : PChar); public; cdecl;
procedure Func1(p:TSTRUCT_RECORD); public; cdecl;
procedure Print(S: PChar); public; cdecl;
var str:string;
begin
frmLua.Memo.Lines.Append(S);
end;
procedure Func1(p:TSTRUCT_RECORD);public; cdecl;
var obj:TLIST_RECORD;
begin
obj.ID:=p.ID;
obj.ID1:=p.ID1;
end;
When the program is run, I get "Enter" once. The table TABLE1
has 6 components. Why is the struct not received in Pascal? Thanks!