【发布时间】:2015-02-16 13:58:00
【问题描述】:
我有一个名为 frameActions 的表,在某些情况下它不能包含某些属性:
action = 'UP'
frameActions = {}
frameActions['UP'] = { a = 1, b = 2 }
如何检查表是否有特定的属性名称?
if frameActions[action].c ~= nil then
-- do something
end
这种情况会抛出错误:attempt to index a nil value
【问题讨论】:
-
if frameActions[action] and frameActions[action].c then
标签: lua conditional-statements null lua-table