More work on lua, fixed a crash that could occur on shutdown, add missing event.