lua state machine taking advantage of first class functions.