As merlight said, if you are going to use function SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex), much easier (and faster) is just checking data you get from this function.
Lua Code:
local function IsSlotProtected(_iBagId, _iSlotId)
local slotData = SHARED_INVENTORY:GenerateSingleSlotData(_iBagId, _iSlotId)
if slotData and slotData.FilterIt_CurrentFilter then
return true
end
return false
end
At first I wanted to add condition "slotData.stackCount > 0" to the function above, but it is not necessary. SHARED_INVENTORY checks it before storing slot data into the bag cache, so stackCount must be always more then zero.
Q: When slotData could be nil even if slot is not empty?
A: If you are using SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex) directly from the EVENT_INVENTORY_SINGLE_SLOT_UPDATE handler, it is possible that your function is called before bag cache is updated. If you want to be sure that cache is updated, use SHARED_INVENTORY's callbacks instead.
Example:
Lua Code:
local function OnFullInventoryUpdated(bagId)
--some code here
end
local function OnInventorySlotUpdated(bagId, slotIndex)
--some code here
end
SHARED_INVENTORY:RegisterCallback("FullInventoryUpdate", OnFullInventoryUpdated)
SHARED_INVENTORY:RegisterCallback("SingleSlotInventoryUpdate", OnInventorySlotUpdated)