在Lua 5.2(集成在Delphi中)中使arg在varag函数中工作 [英] Getting arg to work in a varag function in Lua 5.2 (integrated in Delphi)

查看:202
本文介绍了在Lua 5.2(集成在Delphi中)中使arg在varag函数中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Lua 5.2 API时,下面的代码显示为"nil"

When using the Lua 5.2 API, the code below prints "nil"

function __debug(szName, ...)
    print(type(arg));
end

__debug("s", 1, 2, 3, 4);

但是此代码在使用Lua 5.1时有效,并显示表"

But this code does work when using Lua 5.1, and prints "table"

推荐答案

如果您引用的是vararg函数,则arg table.pack 来如果需要,请创建arg:

If you are referring to vararg function, the arg table was deprecated already in Lua 5.1. In Lua 5.2, you can use table.pack to create arg if you need it:

function debug(name, ...)
    local arg = table.pack(...)
    print(name)
    for i=1,arg.n do
        print(i, arg[i])
    end
end

这篇关于在Lua 5.2(集成在Delphi中)中使arg在varag函数中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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