Lua:获取参数的文字名称 [英] Lua: Get the literal name of the parameter

查看:141
本文介绍了Lua:获取参数的文字名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,

 函数test(a)
name = nameof(a)
print (名称)
结束

测试(def) - 应该打印def

是否有任何lua技巧来实现与上述类似的功能?




不是任何人需要解释为什么他们想要做点什么;如果没有给出真实的例子,有些人会变得脾气暴躁。因此:
$ b $ pre $ 本地函数registerTestSuite(suite)
if(LUnit)then
LUnit:AddTestSuite(
HotNReady .._.. GetVariableName(suite),--HotNReady_PizzaTestSuite
suite);
end;
end;


解决方案



如果确实需要,请尝试 Metalua


For example,

function test (a)
    name = nameof(a)
    print(name)
end

test(def) --should print "def"

Are there any lua tricks to implement something similar to the above?


Not that anyone needs to explain why they want to do something; some people get grumpy if they aren't given a real-life example. So:

local function registerTestSuite(suite)
   if (LUnit) then
      LUnit:AddTestSuite(
            HotNReady.."_"..GetVariableName(suite), --HotNReady_PizzaTestSuite
            suite);
   end;
end;

解决方案

What you asking for is not possible in pure Lua.

If you really need this, try fiddling with Metalua.

这篇关于Lua:获取参数的文字名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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