Skip to content

Make KeyValues.Rewind traversal-stack clearing optional#1993

Merged
asherkin merged 2 commits intoalliedmodders:masterfrom
sirdigbot:rewind-with-stack
Apr 17, 2023
Merged

Make KeyValues.Rewind traversal-stack clearing optional#1993
asherkin merged 2 commits intoalliedmodders:masterfrom
sirdigbot:rewind-with-stack

Conversation

@sirdigbot
Copy link
Contributor

As suggested by asherkin in the discord.
Hopefully implemented properly; not sure if there's other behaviour I'm not factoring in.
Tested with the following code:

char data[] = 
"\"TestRoot\""
... "{"
... "    \"node 1\""
... "    {"
... "        \"node 2\""
... "        {"
... "            \"somekey\" \"somevalue\""
... "        }"
... "    }"
... "}";

public void OnPluginStart()
{
    KeyValues kv = new KeyValues("blah");
    kv.ImportFromString(data);

    kv.JumpToKey("node 1");
    PrintToServer("1. nodes: %i", kv.NodesInStack());
    
    kv.JumpToKey("node 2");
    PrintToServer("2. nodes: %i", kv.NodesInStack());
    
    kv.JumpToKey("somekey");
    PrintToServer("3. nodes: %i", kv.NodesInStack());
    
    
    kv.Rewind();
    PrintToServer("rw1. nodes: %i", kv.NodesInStack());
    PrintToServer("goback: %i", kv.GoBack());
    

    kv.JumpToKey("node 1");
    PrintToServer("4. nodes: %i", kv.NodesInStack());
    
    kv.JumpToKey("node 2");
    PrintToServer("5. nodes: %i", kv.NodesInStack());
    
    kv.JumpToKey("somekey");
    PrintToServer("6. nodes: %i", kv.NodesInStack());
    
    
    kv.Rewind(false);
    PrintToServer("rw2. nodes: %i", kv.NodesInStack());
    PrintToServer("goback: %i", kv.GoBack());
}

image

Copy link
Member

@asherkin asherkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor doc comment, then this is good to go I think.

I'm not super familiar with this area either, but what you've implemented is what I expected it to look like at least!

Copy link
Member

@asherkin asherkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@asherkin asherkin merged commit 50b4ad4 into alliedmodders:master Apr 17, 2023
@sirdigbot sirdigbot deleted the rewind-with-stack branch April 27, 2023 10:51
StarterX4 pushed a commit to StarterX4/sourcemod that referenced this pull request Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants