
function(project_state_change project_handle new_state)
  project_state_get("${project_handle}")
  ans(old_state)
  if("${old_state}_" STREQUAL "${new_state}_")
    return_ref(old_state)
  endif()
  if("${old_state}_" STREQUAL "invalid_")
    message(FATAL_ERROR "invalid state")
  endif()
  set(current_state "${old_state}")
  event_emit(project_on_state_leave ${project_handle} ${old_state} ${new_state})
  assign(!project_handle.project_descriptor.state = new_state)
  set(current_state "${new_state}")
  event_emit(project_on_state_enter ${project_handle} ${old_state} ${new_state})
  return_ref(old_state)
endfunction()
