From 8f5bc8a424877fcbd31e2cb496c3b3528e95f180 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 10 Dec 2017 15:35:56 +0000 Subject: [PATCH] Added table.autokey --- locale/StdLib/table.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/locale/StdLib/table.lua b/locale/StdLib/table.lua index b22246c1..557b2beb 100644 --- a/locale/StdLib/table.lua +++ b/locale/StdLib/table.lua @@ -483,4 +483,15 @@ function table.json(lua_table) if only_indexs then return "["..table.concat(result,",").."]" else return "{"..table.concat(result,",").."}" end +end + +--- Returns the closest match to a key +-- @usage tbl = {foo=1,bar=2} +-- table.autokey(tbl,'f') -- return 1 +function table.autokey(tbl,str) + local _return = {} + for key,value in pairs(keys) do + if string.contains(string.lower(string),string.lower(key)) then table.insert(_return,value) end + end + return _return[1] or false end \ No newline at end of file