参数隐式“arg"在 Lua 中不起作用的函数 [英] Parameter implicit "arg" in functions not work in Lua

查看:18
本文介绍了参数隐式“arg"在 Lua 中不起作用的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

function listar_um (...)对于 ipairs(arg) 中的 i,v 做打印(usando args" .. arg[i])结尾结尾listar_um("Olá", 1, "Dois")

此代码与声明变量 lista 一起使用.

function listar_um (...)列表 = {...}对于 ipairs(lista) 中的 i,v 做打印(não usando args"..lista[i])结尾结尾listar_um("Olá", 1, "Dois")

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

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

谢谢.

解决方案

第一版 PiL 谈论 Lua 5.0.arg 的使用在 Lua 5.0 中可用,但从 Lua 5.1 开始被移除

您可以在 Lua 5.0 参考手册中找到它,但不在 Lua 5.1 参考手册中.

在线解释器使用的版本是Lua 5.2,你可以通过找到打印(_VERSION).

<小时>

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

I have a problem in use implicit parameter arg in functions.

The code not works. The documentation, http://www.lua.org/pil/5.2.html, should works.

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

This code works with the declaring variable 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")

Why the first example does not work?

Script for test: http://www.codeshare.io/IPwRJ Execute on-line script: http://www.compileonline.com/execute_lua_online.php

Thanks.

解决方案

The first edition of PiL talks about Lua 5.0. The use of arg is available in Lua 5.0, while it's removed since Lua 5.1

You can find it in Lua 5.0 reference manual, but not in Lua 5.1 reference manual.

The edition the online interpreter uses is Lua 5.2, you can find out by print(_VERSION).


Edit: after some tests, it seems that arg is still available in Lua 5.1, but not working in Lua 5.2.

这篇关于参数隐式“arg"在 Lua 中不起作用的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆