Skip to content

Commit

Permalink
catch nil dereference if "get_stack" is called on an empty slot
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Jan 5, 2021
1 parent 0eeebb4 commit c365103
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions technic_chests/digilines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ function technic.chests.digiline_effector(pos, _, channel, msg)
elseif msg.command == "get_stack" and type(msg.index) == "number" then
local stack = inv:get_stack("main", msg.index)
local item = stack:to_table()
local def = minetest.registered_items[stack:get_name()]
item.groups = def and table.copy(def.groups) or {}
digilines.receptor_send(pos, digilines.rules.default, set_channel, item)
if item then
-- item available at that slot
local def = minetest.registered_items[stack:get_name()]
item.groups = def and table.copy(def.groups) or {}
digilines.receptor_send(pos, digilines.rules.default, set_channel, item)
else
-- nothing there, return nil
digilines.receptor_send(pos, digilines.rules.default, set_channel, nil)
end

elseif msg.command == "contains_item" and (type(msg.item) == "string" or type(msg.item) == "table") then
local contains = inv:contains_item("main", msg.item)
Expand Down

2 comments on commit c365103

@OgelGames
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know to_table() could return nil... 👀

@BuckarooBanzay
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mine test 😋 (didn't know either...)

Please sign in to comment.