gpt4 book ai didi

Lua:在返回值中存储未指定数量的项目

转载 作者:行者123 更新时间:2023-12-04 16:20:12 25 4
gpt4 key购买 nike

function foo()
return "a", "b", "c"
end

function bar()
return foo()
end

function process()
-- ...
end

function bar_store()
local v = foo()
process()
return v
end

print(bar()) -- A
print(bar_store()) -- B

结果:

a   b   c           -- A
a -- B

如何让 B 版本像 A 版本一样工作?在“bar_store”中,我需要调用可能会返回任意数量返回值的函数,但我需要在函数调用后做一些工作(在我的示例中为“process”)

最佳答案

好吧,回答你自己的问题有点蹩脚,但是:

function bar_store()
local v = {foo()}
process()
return unpack(v)
end

关于Lua:在返回值中存储未指定数量的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6801698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com