Counterpart to https://github.com/godotengine/godot/pull/60199. Also syncs the extension API with that PR.