gpt4 book ai didi

lua - 函数中的参数隐式 "arg"在 Lua 中不起作用

转载 作者:行者123 更新时间:2023-12-01 00:58:25 25 4
gpt4 key购买 nike

我在使用隐式参数 arg 时遇到问题在函数中。

该代码不起作用。文档,http://www.lua.org/pil/5.2.html ,应该有效。

function listar_um (...)
for i,v in ipairs(arg) do
print("usando args " .. arg[i])
end
end
listar_um("Olá", 1, "Dois")

此代码适用于声明变量 lista .
function listar_um (...)
lista = {...}

for i,v in ipairs(lista) do
print("não usando args " .. lista[i])
end
end
listar_um("Olá", 1, "Dois")

为什么第一个例子不起作用?

测试脚本: http://www.codeshare.io/IPwRJ
执行在线脚本: http://www.compileonline.com/execute_lua_online.php

谢谢。

最佳答案

The first edition of PiL谈论 Lua 5.0。 arg的使用在 Lua 5.0 中可用,而在 Lua 5.1 后被移除

您可以在 Lua 5.0 reference manual 中找到它,但不在 Lua 5.1 reference manual .

版本the online interpreter使用的是Lua 5.2,你可以通过print(_VERSION)找到.

编辑 : 经过一些测试,似乎arg在 Lua 5.1 中仍然可用,但在 Lua 5.2 中不起作用。

关于lua - 函数中的参数隐式 "arg"在 Lua 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25664301/

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