~gpcf/advtrains-devel

Fix section_occupancy: Return empty table v1 PROPOSED

Blockhead: 1
 Fix section_occupancy: Return empty table

 1 files changed, 1 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~gpcf/advtrains-devel/patches/53128/mbox | git am -3
Learn more about email & git

[PATCH] Fix section_occupancy: Return empty table Export this patch

Fixes the functioning of the LuaATC function section_occupancy in
the presence of no trains.

Currently, if there is no train in the section,
advtrains.interlocking.db.get_ts will return a table with a nil entry.
When that nil value is passed to table.copy, Minetest throws out an error.
Instead of passing nil to table.copy, just make a new empty table.
---
 advtrains_luaautomation/environment.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua
index 6df5248..761e227 100644
--- a/advtrains_luaautomation/environment.lua
+++ b/advtrains_luaautomation/environment.lua
@@ -233,7 +233,7 @@ if advtrains.interlocking then
		ts_id = tostring(ts_id)
		local response = advtrains.interlocking.db.get_ts(ts_id)
		if not response then return false end
		return table.copy(response.trains)
		return (response.trains and table.copy(response.trains)) or {}
	end
end

-- 
2.39.2