你可以比较一下“类型”在Lua的桌子或元表?

我在Lord the the Rings Online(LOTRO)Beta Lua脚本编写功能中调用了API函数。 API方法返回一个名为ClassAttributes的“类型”,它将在给定的类属性“类型”上。我说“类型”因为当我在返回值上调用
type()
时,它表示它是一个表。 有没有办法让我检查类型或metatable类型?例如。:
local returnedTable = player:GetClassAttributes();

if (returnedTable.Name == "CaptainClassAttributes")
    print("You are playing a captain");
end
UPDATE 以下代码是我使用的:
player = Turbine.Gameplay.LocalPlayer.GetInstance();

Turbine.Shell.WriteLine("player:GetClass():" .. player:GetClass());
Turbine.Shell.WriteLine("Turbine.Gameplay.Class.Captain:" .. Turbine.Gameplay.Class.Captain);

if (player:GetClass() == Turbine.Gameplay.Class.Captain) then
    Turbine.Shell.WriteLine("You are playing a captain");
end
这是输出:   玩家:的getClass():24   Turbine.Gameplay.Class.Captain:24   你在扮演一个队长     
已邀请:
API文档有点令人困惑,虽然我想我找到了你想要的东西。 以下代码应告诉您玩家是否是队长:
local player = Turbine.Gameplay.Player
if (player:GetClass() == Turbine.Gameplay.Class.Captain) then
    print("You are playing a captain")
end
Captain是Gameplay.Class表的成员,该表只是从文档中读取的整数。 注意:您不需要使用“;”结束Lua句子。 无法测试它。希望它有效。     
如果你有这些值的可能元表的列表,你可以使用getmetatable(obj)函数获取它们的metatable,并将它们与你已经拥有的元素进行比较。无法访问LOTRO API,我无法详细说明这个主题:我在哪里可以阅读它? 当然,这假设GetClassAttributes()函数返回的表具有自身的元表,并且可以区分它的metatable和其他类的属性表。     

要回复问题请先登录注册