almost finished rule machine in lua