vrld/hump — pull request #36 by jessevanherk (2014-07-01 17:53:56+00:00)
Title: add assertions to catch incorrect colon-calls to gamestate

If you accidentally call gamestate:switch() instead of gamestate.switch(), your game hangs before getting to the new state. Specifically, it tries using GS as the 'to' state and calls GS:enter, which the __index metamethod tries to find, which passes GS in, and so on, leading to infinite recursion.

This commit adds 2 simple assertions to tell the coder when they've made this hard-to-spot mistake. Because GS.switch and GS.push are not called frequently in normal usage, the extra checks shouldn't adversely affect performance.

An alternative solution would be to detect and limit the recursion somehow, but that wouldn't be as helpful to the programmer as these asserts.