有没有比这更有效的方法来处理 argv 函数?
ffi.cdef [[
void fooArgv(int argc, const char ** argv, const size_t * argvlen);
]]
local foo = function(...)
local nargs = select("#", ...)
local argv = { }
local argvlen = { }
for i = 1, nargs do
local v = tostring( (select(i, ...)) )
argv[i] = v
argvlen[i] = #v
end
return ffi.C.fooArgv(
nargs,
ffi.new("const char * [" .. nargs .. "]", argv),
ffi.new("const size_t [" .. nargs .. "]", argvlen)
)
end
end