Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a PluginIterator methodmap #1779

Merged
merged 13 commits into from
Jun 24, 2022

Conversation

Deathreus
Copy link
Contributor

@Deathreus Deathreus commented Jun 10, 2022

This follows the behavior of OOP

Full disclosure, I wrote this a month ago and forgot
BONUS: Fix a stray space...

@JoinedSenses
Copy link
Contributor

JoinedSenses commented Jun 10, 2022

methodmap is mixing tabs and spaces at beginning.
image

methodmaps through SM are using double slash comments as well rather than /**
image

I think it would make sense to mirror the behavior of the CommandIterator/FrameIterator with a method called Next and a property or method to retrieve the current value.

@Deathreus
Copy link
Contributor Author

Deathreus commented Jun 10, 2022

Haha, copy-paste go brr

I concur that a Plugin property makes more sense than following the native naming

plugins/include/sourcemod.inc Outdated Show resolved Hide resolved
Copy link
Member

@Headline Headline left a comment

Choose a reason for hiding this comment

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

LGTM, will let this cool before I merge

@peace-maker
Copy link
Member

peace-maker commented Jun 10, 2022

Meh, this is weird, since this iterator behaves differently from other iterator methodmaps like CommandIterator and FrameIterator.

This one advances the iterator when reading a property and only returns if there are more in the Next() function. The other ones advance the iterator in the Next() function and allow you to read the values of the current iteration multiple times. I think the latter behavior is more intuitive and we should reimplement the plugin iterator properly while we have the chance here!

See #819

@Deathreus
Copy link
Contributor Author

Deathreus commented Jun 10, 2022

I thought that MorePlugins advanced the iterator, huh

I should have something better ready by tonight

@Deathreus
Copy link
Contributor Author

I think this looks sane

@peace-maker
Copy link
Member

Thank you! This looks better, but the usage pattern of a while(it.Next()) loop would skip the first plugin at the moment.

PluginIterator it = new PluginIterator();
while (it.Next()) {
    char pluginName[128];
    GetPluginFilename(it.Plugin, pluginName, size of(pluginName));
    PrintToServer("%s", pluginName);
}
delete it;

@Deathreus
Copy link
Contributor Author

Deathreus commented Jun 11, 2022

Interesting, I'll have to think on that as I don't think changing core interface behavior would be advised

I was in the mindset of for loops as that's usually what I do iterators in

@psychonic
Copy link
Member

The change would be able to be made for only the methodmap version, to be consistent with the other methodmap iterators, while keeping the non-methodmap behavior as-is so to not break existing plugins.

@Deathreus
Copy link
Contributor Author

Sanity check

/**
* Returns an iterator that can be used to search through plugins.
*
* @return Handle to iterate with. Must be closed via
* CloseHandle().
* @error Invalid Handle.
*/
native Handle GetPluginIterator();
native PluginIterator GetPluginIterator();
Copy link
Member

Choose a reason for hiding this comment

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

The non-methodmap API is now incompatible with the methodmap api. An iterator created with GetPluginIterator still skips the first entry if you use the methodmap api afterwards.

Maybe it's better to change the non-methodmap implementation to use the new iterator class as well to be consistent. Otherwise we'd need to create a new handle type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, I missed this

Copy link
Member

@peace-maker peace-maker left a comment

Choose a reason for hiding this comment

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

Thank you, this looks solid now!

GetPluginIterator returns an handle of the same handletype as PluginIterator(), so it could potentially be used with the methodmap api after view_as<PluginIterator>, but that is such an obviously unnecessary pattern that I'm fine to blame the user in this case :D

We can switch GetPluginIterator to use the new iterator and return a PluginIterator in a follow up patch if needed.

@peace-maker peace-maker merged commit 37c2a83 into alliedmodders:master Jun 24, 2022
@Deathreus
Copy link
Contributor Author

👍

@Deathreus Deathreus deleted the pluginiterator branch June 24, 2022 20:35
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.

5 participants