加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

function – 我不明白的Lua语法片段

发布时间:2020-12-14 21:48:39 所属栏目:大数据 来源:网络整理
导读:我正在使用基于Lua的产品,我正在使用他们的API,并且在那里有一些我不理解的语法. 这是什么? 它是Add的函数调用,如果是,那么输入参数是什么 – 没有将该表分配给变量输入 – 没有等号? 它是Add的函数定义 – 看起来很奇怪,没有任何实现并指定输入表中的内容
我正在使用基于Lua的产品,我正在使用他们的API,并且在那里有一些我不理解的语法.

这是什么?
它是Add的函数调用,如果是,那么输入参数是什么 – 没有将该表分配给变量输入 – 没有等号?

它是Add的函数定义 – 看起来很奇怪,没有任何实现并指定输入表中的内容?

添加包含表格的表格?我从未见过用括号而不是花括号创建的表格?

serviceDefinitions.Add(
    input { name="p1",baseType="NUMBER",description="The first addend of the 
    operation" },input { name="p2",description="The second addend of the operation" },output { baseType="NUMBER",description="The sum of the two parameters" },description { "Add two numbers" }
)

解决方法

当调用只有一个参数是表或字符串的函数时,可以省略括号.从 manual:

All argument expressions are evaluated before the call. A call of the form f{fields} is syntactic sugar for f({fields}); that is,the argument list is a single new table. A call of the form f'string' (or f"string" or f[[string]]) is syntactic sugar for f('string'); that is,the argument list is a single literal string.

这意味着以下函数调用有效:

somefunction({1,2,3,4})
somefunction{1,4}

或者,使用字符串:

print('hello!')
print 'hello!'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读