我想将存储字符串的Lua表传递给c函数。例如,如果我有
tStr = {"String1", "String2", "String3"}
我如何传递给C函数。我想我必须打电话给ffi.new,但是我不确定哪种类型。
local cVar = ffi.new("??" , tStr) -- I am not sure what to pass as type
范围
同样在C函数中,我不确定如何访问整个数据,它是否是指向string的字符串指针** str?
void cFunction(**str); --What pointer type should be used here ??
...很抱歉,如果我错过了一个明显的问题。但是我只是从Lua&ffi开始。所以我仍然不了解大多数事情。
这是一个简单的示例:
local ffi = require"ffi"
ffi.cdef"int execvp(const char*file, const char**argv);"
local arg = ffi.new("const char*[3]", {"ls", "-l"})
ffi.C.execvp(arg[0], arg)
请注意,常数3(数组的大小)
等于2(从Lua传递的字符串数{"ls", "-l"}
)
加1(数组中的最后一个元素实际上是一个零终止符)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句