Skip to content

Nested table without a key is not delimited #4

@whc2001

Description

@whc2001

It's me again, lol.

If a nested table does not have a key (array-like member), then it is not delimited from the last token.

            LTable outer = new LTable();
            LTable inner1 = new LTable();
            LTable inner2 = new LTable();

            outer.Add(1);
            outer.Add(inner1);
            outer.Add("A");

            inner2["test1"] = 1;
            inner2["test2"] = 2;

            inner1.Add(4);
            inner1.Add(5);
            inner1.Add(inner2);

            Console.WriteLine(outer.ToString());

I~9QC$V0P7R7VT%DQSP9KK4

However if it has a key (dict-like member), then it seems fine.

            LTable outer = new LTable();
            LTable inner1 = new LTable();
            LTable inner2 = new LTable();

            outer.Add(1);
            outer.Add(inner1);
            outer.Add("A");

            inner2["test1"] = 1;
            inner2["test2"] = 2;

            inner1.Add(4);
            inner1.Add(5);
            inner1.Add("testkey", inner2);    // <- Add a key

            Console.WriteLine(outer.ToString());

IAU HMIO_FSTKKBSA3EUY5C

Again after some trial-and-error debugging, seems like WriteStartTable() in LuaTableTextWriter.cs is not designed to delimit the last value as it simply goes to TableStart state.

/// Writes the beginning of a Lua table.
/// </summary>
public virtual void WriteStartTable()
{
GotoNextState(Token.TableStart);
Push(LuaContainerType.Table);
Writer.Write('{');
}

If I change line 212 to DelimitLastValue(Token.TableStart);, the problem seems to be solved.

image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions