diff options
Diffstat (limited to 'advtrains/helpers.lua')
-rw-r--r-- | advtrains/helpers.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/advtrains/helpers.lua b/advtrains/helpers.lua index 2160444..c91af34 100644 --- a/advtrains/helpers.lua +++ b/advtrains/helpers.lua @@ -339,3 +339,13 @@ function advtrains.roundfloorpts(pos) return minetest.pos_to_string(advtrains.round_vector_floor_y(pos))
end
+-- insert an element into a table if it does not yet exist there
+-- equalfunc is a function to compare equality, defaults to ==
+-- returns true if the element was inserted
+function advtrains.insert_once(tab, elem, equalfunc)
+ for _,e in pairs(tab) do
+ if equalfunc and equalfunc(elem, e) or e==elem then return false end
+ end
+ tab[#tab+1] = elem
+ return true
+end
|