题
例如,
function test (a)
name = nameof(a)
print(name)
end
test(def) --should print "def"
是否有任何lua技巧可以实现与上述类似的功能?
并非任何人都需要解释为什么他们想做某事;有些人如果得不到真实的例子就会变得脾气暴躁。所以:
local function registerTestSuite(suite)
if (LUnit) then
LUnit:AddTestSuite(
HotNReady.."_"..GetVariableName(suite), --HotNReady_PizzaTestSuite
suite);
end;
end;
解决方案
纯粹的Lua无法满足你的要求。
如果你真的需要这个,请尝试摆弄 Metalua 。
其他提示
尝试使用调试库。
您可以使用 debug.getlocal([thread,] level,local)
来获取有关本地变量的信息,包括其名称。
不隶属于 StackOverflow