From a37b9a291a40d0087321d57650b4f79da624f376 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Thu, 30 Nov 2017 10:01:07 -0800 Subject: [PATCH] fix table.insertkeyed --- src/base/table.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/base/table.lua b/src/base/table.lua index 4e8c3c6e..fed93757 100644 --- a/src/base/table.lua +++ b/src/base/table.lua @@ -255,7 +255,7 @@ -- -- Inserts a value into a table as both a list item and a key-value pair. --- Useful for set operations. +-- Useful for set operations. Returns false if the value already exists, true otherwise. -- function table.insertkeyed(tbl, pos, value) @@ -263,8 +263,14 @@ value = pos pos = #tbl + 1 end + + if tbl[value] ~= nil then + return false + end + table.insert(tbl, pos, value) tbl[value] = value + return true end