Properly handle destruction of Luna states and registered functions.