gpt4 book ai didi

lua - lua返回参数

转载 作者:行者123 更新时间:2023-12-02 07:27:57 26 4
gpt4 key购买 nike

format = function(&Return, Length, Format, ...)
Return = string.format(Format, ...);
Return = string.sub(Format, 0, Length);
return 1;
end

local Test;

format(Test, 12, "Hello world %s! This is a test.", "Hello World");

print(Test);

我希望打印“Hello world!”不是由函数返回,而是由参数返回。

最佳答案

你可以做类似的事情

local function Pointer()
return setmetatable({},{
__tostring = function(self) return self.value end
})
end

format = function(Return, Length, Format, ...)
Return.value = string.sub(Format, 0, Length)
return 1
end

local Test = Pointer()

format(Test, 12, "Hello world %s! This is a test.", "Hello World")

print(Test)

关于lua - lua返回参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25741237/

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