Iterating through an instance

I notice that I can’t iterate through an instance with foreach. I have a need to search through a range of dynamic objects, some of which are instances, some tables, some static classes.

To avoid getting the error message “ERROR: _nexti failed”, I need to check whether the object is an instance with the following:


It’s a bit of a pain. Why can’t instances be iterated?

One upshot of this is that I have to declare any properties in the class at declaration time, rather that at instantiation, otherwise I won’t know that these exist when I iterate the class.

Instances can’t have properties other than the ones declared in the class, and you can’t add properties to a class once it’s been instantiated. But properties added to the class at any point before the first instantiation, appear when the class is iterated over.

Perhaps that’s why (in upstream Squirrel) instances can’t be iterated over. Your code with “typeof” looks like the best solution.