-
Notifications
You must be signed in to change notification settings - Fork 4
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
[BUG] WeightedContainer: can't iterate while I iterate #413
Comments
Yeah I see. This should work: IStack = [];
...
if (_prev == null)
{
if (this.IItems == null)
this.IItems = ::MSU.Table.keys(this.Table);
this.IStack.push(0)
}
_prev = this.IStack.top();
this.IStack[this.IStack.len() - 1]++;
if (_prev == this.Table.len())
{
this.IStack.pop();
if (this.IStack.len() == 0)
this.IItems = null;
return null;
}
return this.IItems[_prev]; |
It will for nested case, it won't for arbitrary intermixed one. Say I create two generators: function iter(cont) {
foreach (k, v in cont) {
print(k + " " + v + "\n")
yield [k v]
}
}
local it1 = iter(cont), it2 = iter(cont);
resume it1;
resume it1;
resume it2;
resume it2;
resume it1; // it2 not finished
resume it2; // bork |
I think you just need a keyToIndex table to iterate and it could be shared across all generators. The behavior if container changes while iterating still might be undefined, which is fine as long as it not crashes, like original tables. |
Nested iteration on squirrel classes with custom I am a proponent of the idea that the class should get a
|
I would certainly call it |
Result:
The text was updated successfully, but these errors were encountered: