如何从Lua传递结构到Pascal

我有Lua表格需要传递数据到Pascal。 以下是我目前使用的方法。

Lua代码:

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代码:

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;

程序运行时,我只得到"Enter"一次。表TABLE1有6个组件。为什么Pascal没有收到结构?谢谢!

点赞