diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..c874d02 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,4 @@ +std = "lua51+luajit+minetest" + +globals = {"test_string_to_table"} +read_globals = {"DIR_DELIM"} \ No newline at end of file diff --git a/alg1.lua b/alg1.lua index 198fd2c..dfe50bc 100644 --- a/alg1.lua +++ b/alg1.lua @@ -1,9 +1,8 @@ local function stringToTable(str) local parseTable -- defined later, but we need it in parseValue - local function parseValue(s, i) - s = s:match("^%s*(.-)%s*$", i) -- Trim leading/trailing spaces - i = 1 + local function parseValue(s, idx) + s = s:match("^%s*(.-)%s*$", idx) -- Trim leading/trailing spaces if s:sub(1, 1) == "{" then return parseTable(s) @@ -47,7 +46,6 @@ local function stringToTable(str) local function parseKey(s, i) s = s:match("^%s*(.-)%s*$", i) -- Trim leading/trailing spaces - i = 1 if s:find("^[%a_]") then local key = s:match("^[%a%d_]*") if key ~= "true" and key ~= "false" and key ~= "nil" then diff --git a/alg2.lua b/alg2.lua index 7c5794f..2b358ab 100644 --- a/alg2.lua +++ b/alg2.lua @@ -55,7 +55,6 @@ local function codedStringToTable(str) local tbl = {} local key, value local next_key = 1 - local inKey = true local depth = 0 local buffer = "" @@ -70,7 +69,7 @@ local function codedStringToTable(str) for i = 1, #str do local char = str:sub(i, i) - + if char == '{' then if depth > 0 then buffer = buffer .. char diff --git a/algtour.lua b/algtour.lua index 281ef27..1091300 100644 --- a/algtour.lua +++ b/algtour.lua @@ -45,7 +45,7 @@ local function parse_key(str) if not success then return false, key end - if key == nil then + if key == nil then return false, "nil cannot be a key" end return true, key @@ -95,7 +95,7 @@ local function stringToTable(str) local success = true local tbl - local replacements = 0 + local replacements local table_count = 0 repeat str, replacements = str:gsub("({[^{}]*})", function (match) diff --git a/init.lua b/init.lua index ab3ed82..aeb69b4 100644 --- a/init.lua +++ b/init.lua @@ -18,7 +18,7 @@ local tests = { "{key1 = 123, key2 = true, key3 = {nestedKey1 = 'value1', nestedKey2 = false}}", "{}", "{ }", "{[{'tables can be'}] = 'keys too'}", - '{\'{table = "that", "contains", a = "string", ["looking"] = {"like", "a"; "table"}}\'}', + '{\'{table = "that", "contains", a = "string", ["looking"] = {"like", "a"; "table"}}\'}', '{[-42.42e42] = 42.42E-42}', '{1, 2, 3, }', -- invalid tables, the code should return an error