在Lisp中,我可以:
(a b c d e f g)
Run Code Online (Sandbox Code Playgroud)
意思是
look up b, c, d, e, f, g
look up a; apply value of a to above
Run Code Online (Sandbox Code Playgroud)
然后,我也可以:
`(a b c d e f g)
Run Code Online (Sandbox Code Playgroud)
这相当于
(list 'a 'b 'c 'd 'e 'f 'g)
Run Code Online (Sandbox Code Playgroud)
现在,在lua,我可以:
[snipplet 1]
foo = {
Foo,
{Cat, cat},
{Dog, dog}
};
Run Code Online (Sandbox Code Playgroud)
最终可能扩展到:{nil,{nil,nil},{nil,nil}}
而我真正想要的是:
[snipplet 2]
{ "Foo", {"Cat", "cat"}, {"Dog", "dog"}}
Run Code Online (Sandbox Code Playgroud)
在lua中有一些类似反引号的方法吗?
我发现[snipplet 1]在视觉上比[snipplet 2]更令人愉悦,但我的意思是snipplet 2.
谢谢!
没有语法,但你可以试试这个运行时解决方案:
setmetatable(_G,{__index=function (t,k) return k end})
Run Code Online (Sandbox Code Playgroud)
这使得所有未定义的变量的行为就像它们包含带有名称的字符串一样.