I need to convert "{table = {}}" to a table.
How to do it in solar 2d
The code below does not work. Tell me what's wrong with it
Please help me find a solution
actionTable = {projectsSettings = {projects = {"Default"}},settings = {projectName = "Default"},blocks = {Default = {ifTouch = {quantityBlocks = "0"},ifStart = {quantityBlocks = "0"}}}}
local function tableToString(tbl)
local result = "{"
for k, v in pairs(tbl) do
-- Check the key type (ignore any numerical keys - assume its an array)
if type(k) == "string" then
result = result..k.." = "
end
-- Check the value type
if type(v) == "table" then
result = result..tableToString(v)
elseif type(v) == "boolean" then
result = result..tostring(v)
else
result = result.."\\".."\""..v.."\\".."\""
end
result = result..","
end
-- Remove leading commas from the result
if result ~= "" then
result = result:sub(1, result:len()-1)
end
return tostring(result.."}")
end
local str1 = tableToString(actionTable)
print(str1.." STR")
tableToString(actionTable)
local tbl1 = loadstring("return "..str1)
print(tbl1["settings"]["projectName"])