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

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

问题描述

例如

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

test(def) --should print "def"

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

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;

推荐答案

你所要求的在纯 Lua 中是不可能的.

What you asking for is not possible in pure Lua.

如果您真的需要这个,请尝试使用 Metalua.

If you really need this, try fiddling with Metalua.

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

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