Skip to content

1.4.0

Choose a tag to compare

@chadhyatt chadhyatt released this 27 Nov 05:16
· 31 commits to master since this release

Changes

  • Add options.InsertCycles flag to API (See below for more info)
  • Use a stack-based system for table depth as opposed to costly call recursion, optimize output concatenation (~20x faster on LargeTableBenchmark)
  • Fix misc. edge-case logic bugs

Manual Cycle Insert Codegen (options.InsertCycles)

By setting the InsertCycles option to true, if there are cyclic references in your table, the output will be wrapped in an anonymous function that adds codegen to manually set paths to those references on the output table. NOTE: If a key in the index path to the cycle is a reference type (e.g. table, function), the codegen can't externally set that path, and it will be ignored.

options.InsertCycles is set to false by default, as potentially wrapping the output table in an anonymous function and storing reference paths during the serialization process may not be ideal for all scenarios.

Example Input:

local Table = {
    {
        "Hello",
        AnotherTable = {},
        ["This can't be indexed raw"] = {}
    },
}

Table.Self = Table
Table[2] = Table[1].AnotherTable
Table["3"] = Table[1]["This can't be indexed raw"]

print(LuaEncode(Table, {
    Prettify = true,
    InsertCycles = true,
    OutputWarnings = false, -- Silence any "warning" codeblocks
}))

Output:

(function(t)
    t.Self = t
    t[2] = t[1].AnotherTable
    t["3"] = t[1]["This can't be indexed raw"]

    return t
end)({
    {
        "Hello",
        AnotherTable = {},
        ["This can't be indexed raw"] = {}
    },
    {},
    Self = {},
    ["3"] = {}
})